【问题标题】:implicitly_wait doesn't work python selenium隐式等待不起作用 python selenium
【发布时间】:2022-06-22 22:35:15
【问题描述】:

我遇到了问题 - 使用implicitly_wait 时不会单击“添加到包”按钮。如果我使用 time.sleep,一切正常,但 time.sleep 是不好的方法。 那么,我需要什么?获取 URl,单击设备,单击“添加到包”按钮。 是的,我知道https://selenium-python.readthedocs.io/waits.htmlhttps://www.selenium.dev/documentation/webdriver/waits/,但这对我没有帮助。请帮帮我)

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import WebDriverException
import time
try:
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://www.oumua.me/shop")# Get URL
    browser.implicitly_wait(10)
    browser.find_element(By.XPATH, '//*[@id="__next"]/div[2]/div/div[1]/div[1]').click() #Click on device button
    browser.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[3]/div[1]').click() #Click Add to the bag that doesn't working

【问题讨论】:

    标签: python selenium selenium-webdriver


    【解决方案1】:

    我可以尝试使用javascript。

    js = 'document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();'
    driver.execute_script(js)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2018-03-27
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      相关资源
      最近更新 更多