当超链接不可见时处理点击

Handle a click when hyperlinks are not visible

我是 selenium 的新手,正在尝试使用 selenium 和 python

自动执行一些网络点击

下面有一个link,它会打开对话框

<li id='upFol'>
<a href='#' title='documents'></a>
.....
</li>

我在 python

中有以下代码
upload = WebDriverWait(driver,5).until(EC.presence_of_element_located((By.XPATH,"//*[@id='upFol']/a")))
upload.click()

这找到了元素并且可以看到点击但对话框没有打开

有没有办法处理这种情况

而不是 presence_of_element_located() 你需要诱导 WebDriverWait for the element_to_be_clickable() and you can use either of the following :

  • 使用CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li#upFol > a[title='documents']"))).click()
    
  • 使用XPATH:

    WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//li[@id='upFol']/a[@title='documents']"))).click()
    
  • 注意:您必须添加以下导入:

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