如何使用 Selenium 和 Python 在突出显示的脚本中单击 webelement

How to click on the webelement with in the highlighted script using Selenium and Python

我试过了:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//*[@value='Sign Out']"))) 

但运气不好..请查看 html 脚本的图片

所需的元素是 JavaScript enabled element so to click on the element you have to induce for the element_to_be_clickable() and you can use either of the following :

  • 使用CSS_SELECTORclick()

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "form[action*='Logoff']>li>input[value='Sign Out']"))).click()
    
  • 使用 XPATHsubmit():

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//form[contains(@action, 'Logoff')]/li/input[@value='Sign Out']"))).submit()
    
  • 注意:您必须添加以下导入:

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