简体   繁体   中英

How to click on the Create Account button within https://mail.protonmail.com/ signup page using Selenium and Python

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()

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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