[英]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 xpath based Locator Strategy :所需的元素是启用GWT的元素,因此要单击必须为
element_to_be_clickable()
诱导WebDriverWait的元素,您可以使用以下基于xpath的定位器策略之一:
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 :使用基于innerHTML的xpath :
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.