Inditly_wait不做工作python selenium
我有问题 - 使用隐式_WAIT时,单击“添加到袋子”的按钮不会发生。如果我使用time.sleep,一切都可以,但是时间。 那么,我需要什么?获取URL,单击设备,单击“添加到袋子”按钮。 是的,我知道 https://selenium-python.readthedthedocs.io/waits.io/waits.html 和,但这对我没有帮助。请帮我)
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
i got problem - click on button 'add to the bag' doesn't happen when using implicitly_wait. If i use time.sleep, all works ok, but time.sleep is bad method.
So, what i need? Get URl, click on device, click on 'add to the bag' button.
Yes, i know about https://selenium-python.readthedocs.io/waits.html and https://www.selenium.dev/documentation/webdriver/waits/ but it not help for me. Please help me)
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许等待它可单击?
Maybe wait for it to be clickable?
我可以尝试使用JavaScript。
I can try to use javascript.
我检查一下,它对我有用,而无需添加
隐式
或explicit
等待,以防万一您不想使用Waits
,您可以尝试下面点击此按钮的方式下方I check and it's working for me without adding the
implicit
orexplicit
wait, in case you do not want to usewaits
, you can try the below way to click on this button我也试图运行它,对我不起作用。看来
browser.page_source
没有时间更新。我认为最好像@data_sc一样使用显式等待。PS在这里有效,但这不是最好的解决方案:
I tried to run it too, it doesn't work for me. It seems that somehow the
browser.page_source
does not have time to update. I think it's better to use explicit waits as @data_sc did.P.S. Here it works, but it's not the best solution: