Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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和chromewebdriver单击hackerrank的登录按钮?_Python_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

Python 如何使用selenium和chromewebdriver单击hackerrank的登录按钮?

Python 如何使用selenium和chromewebdriver单击hackerrank的登录按钮?,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,通过指定按钮的xpath和创建自己的xpath,我尝试了所有可能的方法来单击按钮,但似乎都不起作用。 我提到过 有人能告诉我使用selenium查找并单击此按钮的代码吗?使用以下xpath单击登录按钮 //按钮[.//span[text()=“登录”]] 代码: 或者使WebDriverWait()和元素可点击()并遵循XPath WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[.//s

通过指定按钮的xpath和创建自己的xpath,我尝试了所有可能的方法来单击按钮,但似乎都不起作用。 我提到过


有人能告诉我使用selenium查找并单击此按钮的代码吗?使用以下
xpath
单击登录按钮

//按钮[.//span[text()=“登录”]]

代码:


或者使
WebDriverWait
()和
元素可点击
()并遵循
XPath

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[.//span[text()='Log In']]"))).click()
您需要导入以下库

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

使用以下
xpath
单击登录按钮

//按钮[.//span[text()=“登录”]]

代码:


或者使
WebDriverWait
()和
元素可点击
()并遵循
XPath

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[.//span[text()='Log In']]"))).click()
您需要导入以下库

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
要将字符序列发送到用户名和密码字段,并在登录按钮上单击()
,您可以使用以下任一选项:

  • 使用
    css\u选择器

    driver.get("https://www.hackerrank.com/auth/login")
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input.input[name='username']"))).send_keys("masterchief01")
    driver.find_element_by_css_selector("input.input[name='password']").send_keys("masterchief01")
    driver.find_element_by_css_selector("button[data-analytics='LoginPassword'] span.ui-text").click()
    
  • 使用
    XPATH

    driver.get("https://www.hackerrank.com/auth/login")
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//input[@class='input' and @name='username']"))).send_keys("masterchief01")
    driver.find_element_by_xpath("//input[@class='input' and @name='password']").send_keys("masterchief01")
    driver.find_element_by_xpath("//button[@data-analytics='LoginPassword']//span[@class='ui-text']").click()
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
要将字符序列发送到用户名和密码字段,并在登录按钮上单击()
,您可以使用以下任一选项:

  • 使用
    css\u选择器

    driver.get("https://www.hackerrank.com/auth/login")
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input.input[name='username']"))).send_keys("masterchief01")
    driver.find_element_by_css_selector("input.input[name='password']").send_keys("masterchief01")
    driver.find_element_by_css_selector("button[data-analytics='LoginPassword'] span.ui-text").click()
    
  • 使用
    XPATH

    driver.get("https://www.hackerrank.com/auth/login")
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//input[@class='input' and @name='username']"))).send_keys("masterchief01")
    driver.find_element_by_xpath("//input[@class='input' and @name='password']").send_keys("masterchief01")
    driver.find_element_by_xpath("//button[@data-analytics='LoginPassword']//span[@class='ui-text']").click()
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

使用
提交
方法,而不是
单击
<代码>驱动程序。通过css选择器(“ui btn primary.auth按钮”)查找元素。提交
使用
提交
方法,而不是
单击
<代码>驱动程序。通过css选择器(“ui btn primary.auth按钮”)查找元素。提交