【发布时间】:2021-08-04 15:30:20
【问题描述】:
我正在尝试根据其中的文本找到一个按钮。编译器给了我这个信息:) ...不是有效的 XPath 表达式。
vyber2 = driver.find_elements_by_xpath( '//*[contains(text(), " komplexe Behandlung \"Classic\" ")]')
照片上是下拉菜单的图片。我需要在其中一个选项上找到包名称并单击它。 (比如我需要点击“Komplexe Behandlung Classic”包as shown on this picture。
我打开下拉菜单的代码:
`#open the dropdown menu
vyber1 = driver.find_element_by_xpath(
'//*[@id="packageSelectorContainer"]/div[2]/div/div[1]/div[2]/div')
# Make click in that button
ActionChains(driver).move_to_element(vyber1).click(vyber1).perform()
#wait again
timeout = 5
WebDriverWait(driver, timeout)
try:
element_present = EC.presence_of_element_located((By.ID, '//*[@id="packageSelectorContainer"]/div[2]/div/div[1]/div[2]/ul/li[3]'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
#pick the desired package based on its name
vyber2 = driver.find_elements_by_xpath(
'//*[@id="packageSelectorContainer"]/div[2]/div/div[1]/div[2]/ul/li[3]')
# Make click in that button
ActionChains(driver).move_to(vyber2).click(vyber2).perform()`
感谢您的帮助!
【问题讨论】:
-
你能把链接发布到包含按钮的网页吗?
-
从那个链接,访问按钮所在面板的过程是什么?
-
我更新了问题,以便您可以看到代码...谢谢
-
当我加载页面并单击下拉菜单时,我只看到两个下拉选项,并且每次都会自动选择
komplexe Behandlung "Classic"。下拉选项的数量是否可能会有所不同,或者是否有另一个过程可以切换全套下拉选项(如屏幕截图所示)?