Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.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
填写后如何使用selenium python提交角度表单_Python_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

填写后如何使用selenium python提交角度表单

填写后如何使用selenium python提交角度表单,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,根据您共享的HTML,所需元素是一个元素,因此要在该元素上调用click(),您必须诱导WebDriverWait使该元素可单击,并且您可以使用以下任一解决方案: CSS\u选择器: from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.implicitly_wait(5) driver.maximize_window(

根据您共享的HTML,所需元素是一个元素,因此要在该元素上调用
click()
,您必须诱导WebDriverWait使该元素可单击,并且您可以使用以下任一解决方案:

  • CSS\u选择器

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    driver = webdriver.Firefox()
    driver.implicitly_wait(5)
    driver.maximize_window()
    driver.get("https://xxxxxxxxx.com")
    user = driver.find_element_by_name("username")
    password = driver.find_element_by_name("password")
    user.clear()
    user.send_keys("xxxxxxxx")
    password.clear()
    password.send_keys("xxxxxxx")
    driver.implicitly_wait(5)
    # password.send_keys(u'\ue007')
    # driver.click()
    # driver.implicitly_wait(30)
    # driver.find_element_by_id("login_btn").send_keys(u'\ue007')
    # driver.find_element_by_id('login_btn').send_keys(Keys.ENTER)
    # login_button = driver.find_element_by_xpath("")
    
    
    
    driver.find_element_by_xpath("//[@id='login_btn']").send_keys(u'\ue007')
    # login_button.submit()
    # driver.find_element_by_css_selector(".ModalLoginSignup-loginForm-submitBtn").submit()
    
  • XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn-submit.ModalLoginSignup-loginForm-submitBtn#login_btn"))).click()
    
  • 注意:您必须添加以下导入:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-info btn-large btn-submit ModalLoginSignup-loginForm-submitBtn' and @id='login_btn']"))).click()
    

这不是可点击的元素吗?您是否成功地选择了它,但目前没有与之交互的响应?您确定它是一个表单吗?它看起来像是登录屏幕。它有
标签吗?是的,这是可点击的登录按钮吗?如果是,只需单击它
驱动程序。通过xpath(“/[@id='login\u btn']”查找\u元素。单击()
从selenium导入webdriver#从selenium.webdriver.support.ui从selenium.webdriver.support导入WebDriverWait。支持从selenium.webdriver.support导入预期的\u条件为EC。等待导入WebDriverWait
它工作了。谢谢,但当我把CSS选择器和XPATH放在一起时。真有趣。就像双击一样。
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-info btn-large btn-submit ModalLoginSignup-loginForm-submitBtn' and @id='login_btn']"))).click()
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC