Search code examples
pythonseleniumtwitter

Clicking next button to log into twitter with Selenium


Next

this is the html of the button im trying to click.

s = Service('C:/Users/joeykatz/Desktop/chromedriver1/chromedriver')
driver = webdriver.Chrome(service=s)
# Selenium opens up webpage
driver.get("https://twitter.com/i/flow/login?input_flow_data=%7B%22requested_variant%22%3A%22eyJoaWRlX21lc3NhZ2UiOiJ0cnVlIiwicmVkaXJlY3RfYWZ0ZXJfbG9naW4iOiJodHRwczovL3R3aXR0ZXIuY29tL2kvb2F1dGgyL2F1dGhvcml6ZT9zdGF0ZT12RkpVMVdDVmYxTDNlVlpqQUU0Z1ZWT1hmNmZHSkEmcmVzcG9uc2VfdHlwZT1jb2RlJnJlZGlyZWN0X3VyaT1odHRwcyUzQSUyRiUyRnd3dy5zcG9ydHNkYXRhbm93LmNvbSUyRiZzY29wZT1kbS5yZWFkJTIwdHdlZXQucmVhZCUyMHVzZXJzLnJlYWQlMjBvZmZsaW5lLmFjY2VzcyZjbGllbnRfaWQ9YUVGMVdYWnZhVzB5WlVKTFV6STFTMFV4VGt3Nk1UcGphUSZjb2RlX2NoYWxsZW5nZV9tZXRob2Q9UzI1NiZjb2RlX2NoYWxsZW5nZT1MOW9xTGsySnhWQTU2TG85Z3d2T1JMWWJ4cWVMNks0QkZYTW4weXhnNmxFIn0%3D%22%7D")

time.sleep(10)
username_input = driver.find_element(By.NAME, "text")
username_input.send_keys('[email protected]')
time.sleep(2)

next = driver.find_element(By.CLASS_NAME, "css-901oao r-1awozwy r-6koalj r-18u37iz r-16y2uox r-37j5jr r-a023e6 r-b88u0q r-1777fci r-rjixqe r-bcqeeo r-q4m81j r-qvutc0")
next.click()

Every time it runs I get a Unable to locate element: {"method":"css selector","selector":".css-901oao r-1awozwy r-6koalj r-18u37iz r-16y2uox r-37j5jr r-a023e6 r-b88u0q r-1777fci r-rjixqe r-bcqeeo r-q4m81j r-qvutc0"} error. Any help would be much appreciated


Solution

  • Try the following xpath:

    next = driver.find_element(By.XPATH, "//span[text()='Next']")
    next.click()