我希望得到一些帮助:它使用这个XPATH找到了一个元素:
driver.find_element(By.XPATH, "//*[contains(text(), '100')]")
但是,当单击时,我会得到ElementNotInteractableException。然后,我试着像这样解决它:
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:
<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>发布于 2022-02-07 22:39:45
你可以使用这个函数,如果它准备好了,它会给你一个元素,否则你就没有了。
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 Nonehttps://stackoverflow.com/questions/71024010
复制相似问题