selenium.common.exceptions.TimeoutException,同时使用Selenium Python中的Expected_conditions present_of_element_located单击按钮时 [英] selenium.common.exceptions.TimeoutException while clicking on a button using expected_conditions presence_of_element_located in Selenium Python
问题描述
我想为Nike帐户创建自动创建.为此,我需要添加一个电话号码.我正在使用Python 3,Selenium和Chrome Webdriver进行编码.这是我当前的代码:
driver.get('https://www.nike.com/de/member/settings')element2 = WebDriverWait(驱动程序,20).until(EC.presence_of_element_located((By.XPATH,"/html/body/div [3]/div/div [6]/div [2]/div [2]/div/form/div [2]/div [5]/div/div/div/div [2]/button)))driver.execute_script("arguments [0] .click();",element2)time.sleep(1)
此代码有时仅适用,我经常收到此错误消息:
追溯(最近一次呼叫最近):< module>中的文件"C:/用户/Marten/PycharmProjects/NikeSNKRS/main.py",第239行.element2 = WebDriverWait(驱动程序,20).until(EC.presence_of_element_located((By.XPATH,"/html/body/div [3]/div/div [6]/div [2]/div [2]/div/form/div [2]/div [5]/div/div/div/div [2]/button)))文件"C:\ Users \ Marten \ PycharmProjects \ NikeSNKRS \ venv \ lib \ site-packages \ selenium \ webdriver \ support \ wait.py",第80行,直到引发TimeoutException(消息,屏幕,堆栈跟踪)selenium.common.exceptions.TimeoutException:消息:
您可能知道解决此问题的方法吗?如果您想检查该页面,我为您创建了一个帐户,您可以使用该帐户访问该站点并检查该站点.
我对编码还很陌生,现在仍然如此,我只是想为自己创建一个小脚本.另外,我对XPath经验不足.我建议所有偶然发现此问题的人通读这篇文章.
>我改用了这个XPath://div [@ class ="mex-mobile-input"]/div/div/div/div [2]/按钮
I want to create an automatic creation for Nike accounts. For that I need to add a phone number. I am coding with Python 3, Selenium and the Chrome Webdriver. This is my current code:
driver.get('https://www.nike.com/de/member/settings')
element2 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[3]/div/div[6]/div[2]/div[2]/div/form/div[2]/div[5]/div/div/div/div[2]/button")))
driver.execute_script("arguments[0].click();", element2)
time.sleep(1)
This codes only works sometimes, I am often getting this error message:
Traceback (most recent call last):
File "C:/Users/Marten/PycharmProjects/NikeSNKRS/main.py", line 239, in <module>
element2 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[3]/div/div[6]/div[2]/div[2]/div/form/div[2]/div[5]/div/div/div/div[2]/button")))
File "C:\Users\Marten\PycharmProjects\NikeSNKRS\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Do you maybe know a way to fix this? If you want to inspect the page, I created an account for you with which you can go onto the site and inspect the site. Click to go to Site
Account credentials:
Mail: eXrWi9TfA5XSfNcu4uv2q1@peter.de
Password: 5By3oq1Bw
I want to click this button:
I was quite new to coding, I still am, and I just wanted to create a little script for myself. Also I was quite unexperienced with XPaths. I recommend everybody who stumbles upon this issue, to read through this article.
I used this XPath, instead:
//div[@class="mex-mobile-input"]/div/div/div[2]/button
这篇关于selenium.common.exceptions.TimeoutException,同时使用Selenium Python中的Expected_conditions present_of_element_located单击按钮时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!