0

Everything is fine, but when the script ends it does not loop with the json information. It stays in the Protonmail mailbox and the script no longer works. Try to make the browser completely close the pages and do it again but with the other line of json, not the first one but it doesn't work or I don't know how to do it, please help!

Code Selenium Python:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time, json

driver = webdriver.Firefox(executable_path="C:/firefox_webdriver/geckodriver.exe")

with open("mails.json") as json_file:
    data = json.load(json_file)
    
    for p in data["mails"]:

        print(p["name1"] + " checking in!")

        driver.get("https://mega.nz/register")

        time.sleep(7)

        nextPageBtn = driver.find_element_by_css_selector(".accept-cookies")
        nextPageBtn.click()

        userName1 = driver.find_element_by_id("register-firstname-registerpage2")
        userName1.send_keys(p["name1"])

        userName2 = driver.find_element_by_id("register-lastname-registerpage2")
        userName2.send_keys(p["name2"])

        userEmail = driver.find_element_by_id("register-email-registerpage2")
        userEmail.send_keys(p["email"])

        userPass1 = driver.find_element_by_id("register-password-registerpage2")
        userPass1.send_keys(p["pass1"])

        userPass2 = driver.find_element_by_id("register-password-registerpage3")
        userPass2.send_keys(p["pass2"])

        undVer = driver.find_element_by_css_selector(".understand-check > .megaInputs")
        undVer.click()

        chkVer = driver.find_element_by_id("register-check-registerpage2")
        chkVer.click()

        regBtm = driver.find_element_by_css_selector(".register-button")
        regBtm.click()

        time.sleep(5)

        driver.get("https://mail.protonmail.com/login")

        time.sleep(3)

        userProto = driver.find_element_by_id("username")
        userProto.send_keys("YOUR USER PROTONMAIL")

        userProto = driver.find_element_by_id("password")
        userProto.send_keys("PASSWORD")

        userLogin = driver.find_element_by_id("login_btn")
        userLogin.click()

        time.sleep(7)

        verClk = driver.find_element_by_xpath("/html/body/div[2]/div[2]/div/div[1]/section/div/div[2]/div[1]/h4/span[2]")
        verClk.click()

        time.sleep(3)

        verMail = driver.find_element_by_partial_link_text("mega.nz")
        verMail.click()

        time.sleep(5)

        driver.switch_to.window(driver.window_handles[1])
        driver.close()

        time.sleep(5)

        driver.get("https://mega.nz/")

        print(p["name1"] + " its done!") 
        
driver.close()

Code json

{
    "emails": [
        {
            "name1": "Testing",
            "name2": "Testing",
            "email": "test@protonmail.com",
            "pass1": "pass",
            "pass2": "pass"
        },     
        {
            "name1": "Testing",
            "name2": "Testing",
            "email": "test1@protonmail.com",
            "pass1": "pass",
            "pass2": "pass"
        }     
        
    ]
}
1
  • 1) get rid of the sleeping in the script, 2) fix your locators to relative ones, 3) consider using a service that lets you query emails via an API, logging via a GUI to a 3rd party app is flaky, they might and will change the frontend, breaking your script. These are some ideas for improvement.
    – pavelsaman
    Apr 15 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.