Home > Software design >  Unable to click Username element with selenium python
Unable to click Username element with selenium python

Time:09-27

I am trying to a write a bot that can make new ids of protonmail on demand

link = https://account.proton.me/signup

I am able to click and send keys to passwords and repeat password. But I am failing to click on the element of username. I am using selenium Python, my current code is:

WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="email"]'))).click().send_keys(email)

But running into the following exception:

selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
#0 0x5594edc2d693 <unknown>
#1 0x5594eda26b0a <unknown>
#2 0x5594eda5f5f7 <unknown>
#3 0x5594eda5f7c1 <unknown>
#4 0x5594eda92804 <unknown>
#5 0x5594eda7c94d <unknown>
#6 0x5594eda904b0 <unknown>
#7 0x5594eda7c743 <unknown>
#8 0x5594eda52533 <unknown>
#9 0x5594eda53715 <unknown>
#10 0x5594edc7d7bd <unknown>
#11 0x5594edc80bf9 <unknown>
#12 0x5594edc62f2e <unknown>
#13 0x5594edc819b3 <unknown>
#14 0x5594edc56e4f <unknown>
#15 0x5594edca0ea8 <unknown>
#16 0x5594edca1052 <unknown>
#17 0x5594edcbb71f <unknown>
#18 0x7fe71dfa374d <unknown>

CodePudding user response:

as @Prophet answered you should first switch to iframe and then interact with the element but click() method returns None and running send_keys() on None will give an error. Try this instead:

def sendEmail():
    email = "testEmail"
    WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe")))
    el = WebDriverWait(browser,30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="email"]')))
    el.click()
    el.send_keys(email)
    browser.switch_to.default_content()

CodePudding user response:

  1. There are 2 elements on that page matching the '//*[@id="email"]' XPath locator while you need the second one.
  2. The username element you trying to access is inside an iframe.
    Try the following :
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe")))
username = WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="email"]')))
username.click()
username.send_keys(email)

When you finished working inside the iframe don't forget to switch to the default content with

driver.switch_to.default_content()

UPD
edited according to @Tahirhan notes

CodePudding user response:

I write by another python module, it works, you need install chrome extension first by cc.chrome.extension.install_or_update()

from clicknium import clicknium as cc, locator, ui

#cc.chrome.extension.install_or_update()
tab = cc.chrome.attach_by_title_url(url="https://account.proton.me/signup")
tab.find_element_by_xpath('//*[@id="email"]').set_text("test")
  • Related