python - Test execution halts with the xpath and unable to continue through Selenium
问题描述
I'm using xpath to click an "image" that has an "onclick" attribute. I have tried a few different xpaths but I can't get it to work.
HTML:
<img height="16" width="16" class="rollover" alt="Copy" src="images\copy.gif" onclick="TestExtract(93, true);">
py Code:
test_csv_copy_btn = driver.find_element_by_xpath("//img[@onclick='TestExtract(93, true);']").click()
解决方案
As per your code trials, invoking click()
on the desired element won't return anything. So assigning it to a variable will be of no use.
As per the HTML you have provided to click on the desired image you can use either of the following solutions:
css_selector
:driver.find_element_by_css_selector("img.rollover[alt='Copy'][src*='copy'][onclick^='TestExtract']").click()
xpath
:driver.find_element_by_xpath("//img[@class='rollover' and @alt='Copy'][contains(@src,'copy')][starts-with(@onclick,'TestExtract')]").click()
推荐阅读
- php - 通过 PHP 中另一个函数的结果调用函数
- r - 如何在 R 中读取 HDF4 格式的 Cloudsat 数据
- python - 使用 python 脚本从数据库中选择值时,行数始终打印为 -1
- android - 如何以编程方式共享来自 Android 应用程序的特定 1 卡活动视图,例如 Google Analytics 应用程序
- c++ - C ++中相同基础对象的多个键
- javascript - Java Script中函数和命名函数表达式的代码性能和区别
- openldap - 在 openldap 中更改用户的 pwdChangedTime 属性
- mysql - 如何将同一表中的总值显示为一行(在case语句中)?
- java - 带有自定义登录的 Spring Security LDAP 身份验证
- c# - 未经管理员同意,为用户获取所有驱动器,包括来自站点的驱动器