Python 如何使用selenium和chromewebdriver单击hackerrank的登录按钮?
通过指定按钮的xpath和创建自己的xpath,我尝试了所有可能的方法来单击按钮,但似乎都不起作用。 我提到过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
有人能告诉我使用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按钮”)查找元素。提交