硒 - 未找到元素 (python)
Selenium - element not being found (python)
尝试使用 selenium 将键发送到文本框,但即使在使用显式等待后似乎也找不到元素。
注意:我刚开始学习 python 所以我可能在这里遗漏了一些重要的东西。
Selenium 已经能够在该页面之前找到网站上的所有元素(不确定它是否是新页面,因为 URL 没有更改,但页面中的模块会更改)。我已经尝试了所有可能的元素定位方法(XPATH、ID、CLASS_NAME 等),但它似乎无法找到此文本框元素。我尝试使用它来定位页面上的其他元素,但它似乎也无法找到它们。
#My code:
#imported expected_conditions as EC
wait = WebDriverWait(browser, 15)
wait.until(EC.presence_of_element_located((By.XPATH, '//
[@id="payment_amount_value"]')))
#Element:
<input type="text" class="input-mini text_input span10"
id="payment_amount_value" aria-describedby="payment-amount-error-
message" data-submit="paymentAmount">
#Error Message:
Traceback (most recent call last):
File "<string>", line 100, in <module>
File "/anaconda3/lib/python3.6/site-
packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
更改您的 xpath:
wait = WebDriverWait(browser, 15)
the_input = wait.until(EC.presence_of_element_located((By.XPATH, '//input[@id="payment_amount_value"]')))
the_input.send_keys("Bla-bla")
希望对您有所帮助!
感谢您的帮助,Moshe!原来该元素在 iframe 中,我不得不使用以下命令切换到它:
iframe = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="billing-app-container"]/iframe')))
browser.switch_to.frame(iframe)
尝试使用 selenium 将键发送到文本框,但即使在使用显式等待后似乎也找不到元素。
注意:我刚开始学习 python 所以我可能在这里遗漏了一些重要的东西。
Selenium 已经能够在该页面之前找到网站上的所有元素(不确定它是否是新页面,因为 URL 没有更改,但页面中的模块会更改)。我已经尝试了所有可能的元素定位方法(XPATH、ID、CLASS_NAME 等),但它似乎无法找到此文本框元素。我尝试使用它来定位页面上的其他元素,但它似乎也无法找到它们。
#My code:
#imported expected_conditions as EC
wait = WebDriverWait(browser, 15)
wait.until(EC.presence_of_element_located((By.XPATH, '//
[@id="payment_amount_value"]')))
#Element:
<input type="text" class="input-mini text_input span10"
id="payment_amount_value" aria-describedby="payment-amount-error-
message" data-submit="paymentAmount">
#Error Message:
Traceback (most recent call last):
File "<string>", line 100, in <module>
File "/anaconda3/lib/python3.6/site-
packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
更改您的 xpath:
wait = WebDriverWait(browser, 15)
the_input = wait.until(EC.presence_of_element_located((By.XPATH, '//input[@id="payment_amount_value"]')))
the_input.send_keys("Bla-bla")
希望对您有所帮助!
感谢您的帮助,Moshe!原来该元素在 iframe 中,我不得不使用以下命令切换到它:
iframe = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="billing-app-container"]/iframe')))
browser.switch_to.frame(iframe)