Search code examples
pythonseleniumxpathcss-selectorswebdriverwait

Python : Selenium click account creation


I have to automate account creation for few "Senior Citizen" that live in nursing home. (for free, I'm volunteer) I'm figuring out how to click on button like this :

<button type="submit" data-uid="id-3" role="button" class="_2CEO5 _2eWEL _3cHWt _2Jtx4 V9Kxm _1s9tX _2eWEL _3cHWt _2eWEL _3cHWt _2Jtx4 _3cHWt _5Qrl3">
<span class="_100nC"><div class="_2EteE _2WXqV _34xiU _1TcN5 _2WXqV _34xiU" style="border-top-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255);"></div></span><span class="_2HwQ3">Create an Account</span></button>

I tried with on chrome browser , righ-click > copy Xpath

driver.find_element_by_xpath('//*[@id="plex"]/div/div/div/div[1]/form/button')

but the Selenium cant find it

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="plex"]/div/div/div/div[1]/form/button"}

How to click ? Thank for any hints

The url is: https://www.plex.tv/sign-up/


Solution

  • Navigating directly to their login auth iframe link

    from selenium import webdriver
    
    
      
    driver = webdriver.Chrome(executable_path=path)
    driver.implicitly_wait(10)
    driver.get('https://www.plex.tv/sign-up/')
    
    #accept cookies
    driver.find_element_by_xpath('/html/body/div[8]/div/div/div[3]/a[2]').click()
    #navigate to iframe src
    driver.get(driver.find_element_by_id("fedauth-iFrame").get_attribute('src'))
    #input email
    driver.find_element_by_xpath('//*[@id="email"]').send_keys("email@email.com")
    #input password
    driver.find_element_by_xpath('//*[@id="password"]').send_keys('password')
    #submit
    driver.find_element_by_xpath('//*[@id="plex"]/div/div/div/div[1]/form/button/span[2]').click()