首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TimeoutException - Selenium - Python

TimeoutException - Selenium - Python
EN

Stack Overflow用户
提问于 2022-02-07 19:02:52
回答 1查看 92关注 0票数 0

我希望得到一些帮助:它使用这个XPATH找到了一个元素:

driver.find_element(By.XPATH, "//*[contains(text(), '100')]")

但是,当单击时,我会得到ElementNotInteractableException。然后,我试着像这样解决它:

代码语言:javascript
复制
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), '100')]")))
element.click()

然后,我得到了我无法解决的TimeoutException。先谢谢你。

这是插入它的DOM:

代码语言:javascript
复制
<div class="mat-menu-content ng-tns-c83-207">
 <div _ngcontent-xpe-c205="" class="option info-f12-w400-space-gray600 cursor-pointer ng-tns-c83-207">
   <div _ngcontent-xpe-c205="" class="value selected ng-star-inserted"> 25 </div>
   <div _ngcontent-xpe-c205="" class="value ng-star-inserted">50</div>
   <div _ngcontent-xpe-c205="" class="value ng-star-inserted"> 100 </div>
</div>
</div>
EN

回答 1

Stack Overflow用户

发布于 2022-02-07 22:39:45

你可以使用这个函数,如果它准备好了,它会给你一个元素,否则你就没有了。

代码语言:javascript
复制
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
def find_element_by_xpath(self, xpath, delay=5):
    delay = delay  # seconds
    xpath_referrers = xpath
    try:
        my_elem = WebDriverWait(self.browser, delay).until(
            EC.presence_of_element_located((By.XPATH, xpath_referrers)))
        return my_elem
    except TimeoutException:
        print(f"cant find elem at {delay} delay times ")
        return None
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71024010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档