简体   繁体   English

如何使用 Selenium 和 Python 单击启用 GWT 的元素

[英]How to click on GWT enabled elements using Selenium and Python

I'm working with Selenium as a newbie and also as a newbie developer.我正在与 Selenium 作为新手和新手开发人员一起工作。 I try to solve this XPath but with no results that is why I'm looking for help.我尝试解决此 XPath 但没有结果,这就是我寻求帮助的原因。

So I want to click in the checkbox which has a dynamic id but it is not that easy to find this checkbox based on tittle="Viewers"因此,我想单击具有动态 id 的复选框,但根据 tittle="Viewers" 找到此复选框并不容易

Please notice there is a whole list of checkboxes with names on right from a checkbox in div which I want to include in my tests.请注意,在 div 中的复选框右侧有一个完整的复选框列表,我想将其包含在我的测试中。

HTML: HTML:

<span class="row-selection"><input type="checkbox" value="on" id="gwt-uid-2215" tabindex="0"><label for="gwt-uid-2215"></label></span> <div class="row-label" title="Viewers">Viewers</div>

Snapshot;快照;

提供的代码

The desired element is a GWT enabled element so to click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following based Locator Strategy :所需的元素是启用GWT的元素,因此要单击必须为element_to_be_clickable()诱导WebDriverWait的元素,您可以使用以下基于定位器策略之一:

  • Using xpath based on title attribute:基于title属性使用xpath

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@title='Viewers']//preceding::span[1]//label"))).click()
  • Using xpath based on innerHTML :使用基于innerHTMLxpath

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Viewers']//preceding::span[1]//label"))).click()
  • Note : You have to add the following imports:注意:您必须添加以下导入:

     from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium 和 Python 单击启用 ember.js 的按钮 - How to click on the ember.js enabled button using Selenium and Python 如何使用 Selenium 和 Python 单击启用 javascript 的锚元素 - How to click a javascript enabled anchor element using Selenium and Python 如何点击<a>元素</a>列表<ul><a>和</a><li><a>元素与硒使用python?</a> - How to click on the list of the <a> elements in an <ul> and <li> elements with selenium using python? 如何单击使用 selenium python 弹出阻止的元素? - How to click on elements blocked by pop up using selenium python? 在 Python 上使用 selenium 单击多个元素 - Click on multiple elements using selenium on Python 如何使用 Selenium Python 在网站上单击元素 - How to click Elements on websites with Selenium Python Python + Selenium:如何单击“ onclick”元素? - Python + Selenium: How can click on “onclick” elements? 使用 Selenium 和 Python 访问网页时,Selenium 无法单击元素 - Selenium unable to click on elements while accessing a webpage using Selenium and Python 如何使用硒驱动程序单击元素? - How to click on elements using selenium driver? 如何点击列表中的<li>中的元素<ul> python中含有硒的元素? - How to click on the list of the <li> elements in an <ul> elements with selenium in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM