繁体   English   中英

无法单击带有 selenium 的按钮

[英]cant click on Button with selenium

我正在尝试使用 selenium 登录我的 twitter 帐户。 用户名和密码的填写工作完美,但按下登录按钮时没有任何反应。

        self.driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/form/div/div[3]/div').click()

我查看了 html 代码,并且aria-haspopup为假。 有什么方法可以将其设置为 true 以便我可以单击按钮?

问候

您的 xpath 在 twitter 的登录页面( https://twitter.com/login )上运行良好。 也许您正在尝试登录其他页面。

我正在提供一小段代码用于登录 twitter。 我使用了另一个 xpaths 和 WebDriverWait 来等待显示登录表单。

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

driver = webdriver.Chrome()

driver.get('https://twitter.com/login')

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@name='session[username_or_email]' and @data-focusable='true']")))

driver.find_element_by_xpath("//input[@name='session[username_or_email]' and @data-focusable='true']").send_keys('login')
driver.find_element_by_xpath("//input[@name='session[password]' and @data-focusable='true']").send_keys('password')

driver.find_element_by_xpath("//div[@data-testid='LoginForm_Login_Button']").click()

尝试这样做:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()

driver.get('https://twitter.com/login')

email = driver.find_element(By.NAME, 'email')
email.clear()
email.send_keys(EMAIL)
password = driver.find_element(By.NAME, 'pass')
password.clear()
password.send_keys(PASSWORD)

password.send_keys(Keys.RETURN) # Login with ENTER button

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM