Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用selenium填写表单?_Python_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

Python 如何使用selenium填写表单?

Python 如何使用selenium填写表单?,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,我想登录该网站,但无法添加我的凭据 我的代码的第一部分是: 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/kau

我想登录该网站,但无法添加我的凭据

我的代码的第一部分是:

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()

之后,尝试使用
find_element\u by_xpath()
和其他一些方法,但没有一个有效,因为它们要么说“无法定位元素”要么说“元素不可交互”。我怎么做?在前面的示例中,我可以使用
按id查找视图()
找到它,但现在我遇到了一些问题。

要登录该网站,您需要引导
元素成为可点击的()
,您可以使用以下任一选项:

  • 使用
    CSS\u选择器

    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")
    
  • 使用
    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")
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
浏览器快照:


你到底面临什么问题?我想做什么就做什么,你为我节省了很多时间,谢谢!