[英]How do I complete a form using selenium?
I want to log in that website, but can't add my credentials.我想登录该网站,但无法添加我的凭据。
The first part of my code is:我的代码的第一部分是:
from selenium import webdriver
PATH = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.maximize_window()
driver.get('https://glovoapp.com/ro/buc/store/kaufland-buc/')
login = driver.find_element_by_xpath('//*[@id="user-login"]')
login.click()
After that, tried using find_element_by_xpath()
and a few other methods, but none of them worked, as it either says "Unable to locate element" or "element not interactable".之后,尝试使用
find_element_by_xpath()
和其他一些方法,但它们都不起作用,因为它要么说“无法找到元素”,要么说“元素不可交互”。 How can I do it?我该怎么做? In previous examples I have followed I could find it with
find_view_by_id()
but now I encounter some problems.在前面的示例中,我可以使用
find_view_by_id()
找到它,但现在我遇到了一些问题。
To log in that website you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies :要登录该网站,您需要为
element_to_be_clickable()
诱导WebDriverWait并且您可以使用以下任一定位器策略:
Using CSS_SELECTOR
:使用
CSS_SELECTOR
:
driver.get("https://glovoapp.com/ro/buc/store/kaufland-buc/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#user-login"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#login-email div input"))).send_keys("AlexBebereche@stackoverflow.com")
Using XPATH
:使用
XPATH
:
driver.get("https://glovoapp.com/ro/buc/store/kaufland-buc/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='user-login']"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='login-email']//following::input[@data-test-id='text-field-input']"))).send_keys("AlexBebereche@stackoverflow.com")
Note : You have to add the following imports:注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:浏览器快照:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.