Message: u'The given selector btn dropdown-toggle btn-info is either invalid or does not result in a WebElement
html代码:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>button dropdown</title>
<script type="text/javascript" async="" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(
function(){
$('.dropdown-menu').find('a').first().click(function(){ alert('watir-webdriver is better than selenium-webdriver'); });
}
);
</script>
</head>
<body>
<h3>button dropdown</h3>
<div class="row-fluid">
<div class="span3">
<div class="well">
<div class="btn-group">
<a class="btn dropdown-toggle btn-info" data-toggle="dropdown" href="#">
Info
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#">watir-webdriver</a></li>
<li><a href="#">better than</a></li>
<li><a href="#">selenium-webdriver</a></li>
</ul>
</div>
</div>
</div>
</div>
</body>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
</html>
Python 代码:
#coding=utf-8 from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
import os if 'HTTP_PROXY' in os.environ: del os.environ['HTTP_PROXY'] dr = webdriver.Firefox()
file_path = 'file:///' + os.path.abspath('button_dropdown.html')
dr.get(file_path) sleep(1) #
dr.find_element_by_class_name('btn dropdown-toggle btn-info').click()
buttons =dr.find_elements_by_class_name('dropdown-menu')
for btn in buttons:
if btn.text == 'better than': btn.click() sleep(1) dr.quit()
错误信息:InvalidSelectorException: Message: u'The given selector btn dropdown-toggle btn-info is either invalid or does not result in a WebElement.
解决办法:
#coding=utf-8 from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
import os if 'HTTP_PROXY' in os.environ: del os.environ['HTTP_PROXY'] dr = webdriver.Firefox()
file_path = 'file:///' + os.path.abspath('button_dropdown.html')
dr.get(file_path) sleep(1) #点击下拉菜单
dr.find_element_by_link_text('Info').click() #找到dropdown-menu父元素
WebDriverWait(dr,10).until(lambda the_driver: the_driver.find_element_by_class_name('dropdown-menu').is_displayed()) #找到better than
menu = dr.find_element_by_class_name('dropdown-menu').find_element_by_link_text('better than') menu.click() sleep(3) dr.quit()
Message: u'The given selector btn dropdown-toggle btn-info is either invalid or does not result in a WebElement的更多相关文章
- Appium 运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported for (转)
现象:Appium运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported f ...
- RobotFramework+Appium 升级Appium v1.10.0后,执行click element时报错:InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported for this session,解决办法
报错信息如下: debug] [35m[XCUITest][39m Connection to WDA timed out[debug] [35m[XCUITest][39m Connection t ...
- jquery $('#btn').click与$("#btn").live("click",function()有什么区别?
live方法绑定的事件处理函数,在页面中未来添加的元素只要满足原来的选择器,仍然会导致事件触发.普通的事件绑定则没有这个效果.对于#btn这个选择器来说,如果你未来将id为btn的元素删除,然后再创建 ...
- Bootstrap4总结
一. bootstrap简介 Bootstrap,来自 Twitter(全国最大的微博),是目前最受欢迎的前端框架. bootstrap下载及演示 http://v3.bootcss.com 什么是b ...
- Bootstrap 下拉菜单和滚动监听插件
一.下拉菜单 常规使用中,和组件方法一样,代码如下: //声明式用法 <div class="dropdown"> <button class="btn ...
- bootstrap的滚动监听
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...
- python+selenium自动化软件测试(第2章):WebDriver API
2.1 操作元素基本方法 前言前面已经把环境搭建好了,从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可 ...
- Selenium2+python自动化73-定位的坑:class属性有空格
前言 有些class属性中间有空格,如果直接复制过来定位是会报错的InvalidSelectorException: Message: The given selector u-label f-dn ...
- 2.33 定位的坑:class属性有空格
2.33 定位的坑:class属性有空格 前言有些class属性中间有空格,如果直接复制过来定位是会报错的InvalidSelectorException: Message:The given sel ...
随机推荐
- java如何写自己的native方法实现调用本地的c++库?
等待编辑 1:首先可以找一本jni java native interface相关的书籍来看.
- UMG设置组件自适应居中或靠边
转自:http://aigo.iteye.com/blog/2297430 比如你的UI中有些组件需要居中显示,有些需要始终在右上角并且与上边框和右边框保持固定的距离等等,对于这种需要动态适应屏幕分辨 ...
- FDD vs TDD
双工方式 FDD vs TDD 频分双工(FDD) 收发信各占用一个频率. 优点是收.发信号同时进行,时延小,技术成熟,缺点是设备成本高. 时分双工(TDD) 收发信使用同一个频率,但使用不同 ...
- CSS3 的calc()方法的使用
calc()简单介绍 calc()对大家来说,或许很陌生,不太会相信calc()是css中的部分.因为看其外表像个函数,既然是函数为何又出现在CSS中呢?这一点也让我百思不得其解,今天有一同事告诉我, ...
- 对象DIY
1.在java开发中,好代码都是组织的比较好,模拟现实很好,而不是步骤指令 2.对象组织+继承(归类
- Python3 open()函数参数
open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=No ...
- 信息学奥赛(NOIP)初赛学习方法推荐
首先声明:本帖针对初学者,本帖只是列出一个大概的框架,不属于自学方法,有条件有能力,请找一位好老师来教,多跟前辈交流经验.(否则多会出现事倍功半的悲剧!) 一.初赛内容 初赛偏重于基础知识. 1. 一 ...
- python写个御剑
前言: 今天师傅叫我,写个python版的御剑.然后我之前也写过 不过不怎么样,这次有新想法. 思路: 御剑:读取御剑配置文件里的所有路径,加上用户要扫描的url.进行批量检测,如果状态码为200并且 ...
- OMIM 表型和基因如何关联
OMIM数据库:大神私藏的数据库,99.9%的人都不知道! 2019-03-04 11:00乳腺癌/医生/肺癌 “ GEO.NCDB.TCGA.SEER数据库这些我都知道,但OMIM是什么鬼? OMI ...
- uva-167-枚举
题意:八皇后问题,要求选取的总和最大 #include<stdio.h> #include<iostream> #include<sstream> #include ...