繁体   English   中英

单击 Selenium Python 按钮时出现问题

[英]Problem clicking the button Selenium Python

代码

我尝试了这种方法,该方法非常适用于同一网页上的其他按钮(不同类),但不适用于此特定按钮,我也尝试使用 div 类:

xpathoo = '//button[@class="ncss-brand pt2-sm pr5-sm pb2-sm pl5-sm ncss-btn-accent continueOrderReviewBtn mod-button-width ncss-brand\
        pt3-sm prl5-sm pb3-sm pt2-lg pb2-lg d-sm-b d-md-ib u-uppercase u-rounded fs14-sm"]' 
driver.find_element_by_xpath(xpathoo).click()

文本为PASSA ALLA VERIFICA DELL的元素是一个动态元素,因此单击它您必须为element_to_be_clickable()引入WebDriverWait ,您可以使用以下任一定位器策略

  • 使用CSS_SELECTOR

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.continueOrderReviewBtn[data-attr='continueToOrderReviewBtn']"))).click()
  • 使用XPATH

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-attr='continueToOrderReviewBtn' and contains(., 'PASSA ALLA VERIFICA DELL')]"))).click()
  • 注意:您必须添加以下导入:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM