How to click on GWT enabled elements using Selenium and Python

ⅰ亾dé卋堺 提交于 2020-07-23 04:55:11

问题


I'm working with Selenium as a newbie and also as a newbie developer. I try to solve this XPath but with no results that is why I'm looking for help.

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"

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.

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;

Provided code


回答1:


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:

  • Using xpath based on title attribute:

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

    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
    


来源:https://stackoverflow.com/questions/62880706/how-to-click-on-gwt-enabled-elements-using-selenium-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!