简体   繁体   English

Twitter 没有这样的元素错误 python-selenium

[英]Twitter No such element error python-selenium

After printing the username on the login screen on twitter, I want it to press the login button, but I get a "no such element" error.在 twitter 的登录屏幕上打印用户名后,我希望它按下登录按钮,但出现“没有这样的元素”错误。

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")
options.add_argument('--disable-notifications')

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 20)

url = "https://twitter.com/login"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[autocomplete='username']"))).send_keys("bla")
driver.find_element(By.XPATH, "//div[@role='button'][contains(.,'Next')]").click()

i try with do xpath css selector but never work我尝试使用 do xpath css 选择器但从未工作

This code worked for me!这段代码对我有用!
With no changes没有变化

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")
options.add_argument('--disable-notifications')

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)

url = "https://twitter.com/login"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[autocomplete='username']"))).send_keys("bla")
driver.find_element(By.XPATH, "//div[@role='button'][contains(.,'Next')]").click()

The result is - we went to the next page结果是——我们进入了下一页
I tried several times.我试了几次。

在此处输入图像描述

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

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