0

Everything is working except the button. The submit button is not being clicked. Can anyone help me out? I believe it may have to do with the fact that I changed the frame to "top". But, I am unsure how to change it back.

Code:

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
import time

url = 'https://protonmail.com/'

driver = webdriver.Chrome('/Users/edenhikri/Desktop/chromedriver')
driver.get(url)
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'.btn.btn-default.btn-short'))).click()
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'.panel-heading'))).click()
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'#freePlan'))).click()

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,'password'))).send_keys('test123')
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,'passwordc'))).send_keys('test123')

WebDriverWait(driver,20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,".top")))
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,'username'))).send_keys('myUsername')

driver.find_element_by_class_name('btn.btn-submit').click()

error:

no such element: Unable to locate element: {"method":"class name","selector":"btn.btn-submit"}

button code:

<button type="submit" class="btn btn-submit" name="submitBtn">Create Account</button>

I have also tried using xpath but I get the same error that it cannot find this:

driver.find_element_by_xpath("//button[@class=“btn btn-submit”]").click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Eden
  • 31
  • 1
  • 10
  • Is there an error, what happens? Have you checked the page source to ensure that the button is there? – AMC Jul 10 '20 at 03:00
  • I have edited. @AMC – Eden Jul 10 '20 at 03:01
  • Alright, what do you understand from that error message, then? – AMC Jul 10 '20 at 03:19
  • that it cannot locate the button from the class name. I am not sure of another way to find the button. I have inserted the button code. @AMC – Eden Jul 10 '20 at 03:21
  • _I have inserted the button code._ What do you mean? Have you checked the HTML source which the program ends up with to ensure that the element is what you expect? – AMC Jul 10 '20 at 03:22
  • Yes. Look at the edit. I inserted the button's code from the website @AMC – Eden Jul 10 '20 at 03:23
  • 1
    Does this answer your question? [find\_element\_by\_class\_name for multiple classes](https://stackoverflow.com/questions/44759907/find-element-by-class-name-for-multiple-classes) – AMC Jul 10 '20 at 03:26
  • Could you please also give the HTML code in case you are locating the button wrong –  Jul 10 '20 at 03:27
  • @SiddharthAgrawal They already did, and their code looks like a [mcve] anyway. – AMC Jul 10 '20 at 03:27
  • I have added the HTML source code under "button code:" in my post. It is the right button. @SiddharthAgrawal – Eden Jul 10 '20 at 03:28
  • @AMC I have tried using xpath as noted In the answer you shared. It did not work. – Eden Jul 10 '20 at 03:29
  • @Eden The XPath in your post is for a different element entirely, no? – AMC Jul 10 '20 at 03:33
  • That is the xpath given when I press copy xpath on the html code for the button. @AMC – Eden Jul 10 '20 at 03:35
  • @Eden Wait never mind, it could work. Can you try using the XPath `//button[@class=“btn btn-submit”]` ? – AMC Jul 10 '20 at 03:36
  • I tried this `driver.find_element_by_xpath('//button[@class=“btn btn-submit”]').click()`. but it did not work. I go the error `The string '//button[@class=“btn btn-submit”]' is not a valid XPath expression.` @AMC – Eden Jul 10 '20 at 03:39
  • @Eden It might be the quotation marks, try rewriting them? – AMC Jul 10 '20 at 03:43
  • I tried rewriting. It did not fix it. @AMC – Eden Jul 10 '20 at 04:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/217577/discussion-between-eden-and-amc). – Eden Jul 10 '20 at 04:33

2 Answers2

0

Please use this xpath //*[contains(text(),"Create Account")]

Justin Lambert
  • 940
  • 1
  • 7
  • 13
0

The CREATE ACCOUNT button is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use the following based Locator Strategies:

    driver.get("https://protonmail.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-default.btn-short[href='signup']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-plan='free']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#freePlan"))).click()
    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.top[title='Registration form']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#username"))).send_keys("Eden")
    driver.switch_to.default_content()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#password"))).send_keys("Eden")
    driver.find_element_by_css_selector("input#passwordc").send_keys("Eden")
    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.bottom[title='Registration form']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-submit"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

protonmail_create_user

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352