- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个帮助函数来浏览页面并打开它找到的每个帮助按钮。它既漂亮又简单;
def openHelp(ff):
"""
Opens all the help buttons on the screen
@type ff: instance of webdriver
@param ff: firefox instance of webdriver
"""
allHelpButtons = ff.find_elements_by_xpath('//a[@class="helpButton"]')
for helpButton in allHelpButtons:
helpButton.click()
但是,在某些页面上,帮助按钮及其相应字段可能会被 javascript 隐藏,这似乎是当 Selenium 尝试单击这些隐藏按钮时导致 ElementNotVisibileException
的原因。
每个帮助按钮在标记中显示都相同,没有应用 display:none
,所以我无法这样检查。它们看起来是这样的;
<a class="helpButton" title="Help about: Field" href="#">
<img alt="Help about: Field" src="/static/images/helpIcon.png">
</a>
如果存在此异常,我假设必须有一种方法可以用来检查元素是否可见。理想情况下,我只想将所有可见元素收集到我的 allHelpButtons
列表中,但我找不到任何相关文档。我可以使用 xpath 搜索执行检查吗?还是必须在收集元素后对其进行检查?
奖励问题
我还想知道,是否可以通过匹配名称和值来选择列表项。例如,我在页面中将“是/否”单选按钮选择定义为 ul
;
<ul class="compact horizontal ">
<li>
<input id="id_fieldname_0_true" type="radio" value="True" name="fieldname">
<label for="id_fieldname_0_true">Yes</label>
</li>
<li>
<input id="id_fieldname_0_false" type="radio" value="False" name="fieldname">
<label for="id_fieldname_0_false">No</label>
</li>
</ul>
显然,id 是唯一的,但我宁愿能够使用选择器来挑选“名称”和“值”,因为我认为这将使制作通用选择器变得更容易,我可以将值传递给它.
最佳答案
有一个is_displayed
函数。
检查下面的源代码,第 162 行:
https://code.google.com/p/selenium/source/browse/py/selenium/webdriver/remote/webelement.py
至于您的奖励问题,这也是由 XPath 完成的,单击"is"按钮单选:
//label[text()='Yes']/preceding-sibling::input
对于否:
//label[text()='No']/preceding-sibling::input
关于python - 使用 Xpath 单击页面上的所有元素会导致 ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15156375/
此页面的主菜单( linio )有 11 个链接。只对 9 感兴趣(那些具有灰色背景并且悬停时显示子菜单的)。 我想从 9 个选项中单击子菜单中的每个元素。期望的过程是: 1.-第一部分:“Celul
我正在使用 Java selenium 自动输入用户的数据,但他必须通过下拉列表选择状态。我收到异常错误。 我尝试过使用所有选择器: drpState.selectByIndex(5); drpSta
我已经查看了涉及该主题的一些其他问题,但我没有在任何地方看到这个特定问题。我有一个点击 Web 元素的测试。我尝试通过 ID 和 XPath 引用它,并使用 wait.until() 等待它变得可见。
我正在尝试扩展所有评论、回复,在评论中查看更多内容,并在 Facebook 的帖子中查看更多内容。 1)我在下面编写的代码允许我扩展我想要的所有内容,除了帖子中的一些回复,即使我已将回复按钮放在循环中
我使用 EBays 的高级上传工具(URL:http://cgi5.ebay.com/ws/eBayISAPI.dll?NewListing&cpg=20&aid=1&from=wn&sid=5297
我看到很多关于 Selenium 的 ElementNotVisibleException 问题的问题/答案。到目前为止我完成的最好的代码如下: from selenium.webdriver.sup
我正在尝试使用 webdriver 单击链接,但它向我抛出一个 ElementNotVisibleException 说“元素当前不可见,因此可能无法与之交互” 我的网络驱动程序代码: addProg
import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import o
我正在使用 Selenium 和 Python,并且我正在尝试填写登录表单,我已经成功填写用户名字段,但无法填写密码。这是 HTML:
当我试图点击一个按钮时出现以下错误: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible
我正在使用 Selenium Webdriver 登录网站。我尝试了多种不同的选择器,并尝试了隐式等待,但无法找到该元素。 from selenium import webdriver
我目前正在尝试使用 Selenium 进行一些用户界面测试,我遇到了这个很好的方法(不确定我从哪里得到它......),它应该处理不存在的元素和隐藏元素...... 问题在于第二个问题:即使元素未显示
我正在尝试使用我正在使用的 Selenium 进行黑盒测试: Mac 操作系统:版本:10.9.4 java.版本:1.6.0_65 浏览器:firefox 版本 32.0.3 Selenium :版
尝试从多选下拉框中进行选择,发现似乎是一个不错的资源。 我正在研究http://preview.harriscountyfws.org/我正在尝试在“按机构选择”多选下拉列表中选择多个项目。 我在这里
我想做的就是:转到“http://news.google.com”,然后单击侧面菜单上的“技术”链接。这是我的代码: from selenium import webdriver from selen
目前我有此输入 + Add certificate 并且我想将文件发送到同一地址,因此我运行以下代码: self.driver.execute_script("docu
我试图让 selenium 单击 li 元素内的链接。这是在 while 循环内发生的。点击一直有效,直到我到达 li 低于 Firefox 窗口的水平。如果我在 selenium 尝试点击之前在 F
我有一个帮助函数来浏览页面并打开它找到的每个帮助按钮。它既漂亮又简单; def openHelp(ff): """ Opens all the help buttons on the
我正在尝试以编程方式在网站中选择一种货币:http://www.asos.com/asos/asos-skinny-chinos-in-dark-khaki/prd/5542109 但是它给我带来了一
我从来没有认真研究过 HTML,所以我要说的可能是不对的。 当我编写 selenium 代码时,我注意到某些网页上的某些按钮不会重定向到其他页面,但它们会更改第一个页面的结构。据我了解,发生这种情况是
我是一名优秀的程序员,十分优秀!