我几乎完成了自动创建新贝宝账户的脚本。但我希望脚本在退出驱动程序之前使用其他网站的信息。
(我希望脚本打开谷歌邮件,然后创建一个新帐户,然后获得有关谷歌电子邮件的信息[例如:电子邮件=jamescharles@gnail.com]并将其粘贴到Paypal电子邮件地址栏中。
这可能吗?
我可以定义网页,然后让脚本在它们之间快速切换吗?
这是我的全部代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Chrome(executable_path=r"C:UsersASUSDesktopNamePycharmchromedriver.exe")
browser.get("https://www.paypal.com/welcome/signup?country.x=GB")
try:
Recap = WebDriverWait(browser, 90).until(
EC.presence_of_element_located((By.ID, "paypalAccountData_firstName"))
)
finally:
browser.forward()
browser.find_element_by_id("acceptAllButton")
cookies = browser.find_element_by_id("acceptAllButton")
cookies.click()
browser.find_element_by_id("paypalAccountData_countryselector")
GB = browser.find_element_by_id("paypalAccountData_countryselector")
GB.click()
browser.find_element_by_id("paypalAccountData_firstName")
Vorname = browser.find_element_by_id("paypalAccountData_firstName")
Vorname.click()
Vorname.send_keys("James")
browser.find_element_by_id("paypalAccountData_lastName")
Nachname = browser.find_element_by_id("paypalAccountData_lastName")
Nachname.click()
Nachname.send_keys("Charles")
browser.find_element_by_id("paypalAccountData_email")
email = browser.find_element_by_id("paypalAccountData_email")
email.click()
email.send_keys("jamescharles@gmail.com")
browser.find_element_by_id("paypalAccountData_password")
Passwort = browser.find_element_by_id("paypalAccountData_password")
Passwort.click()
Passwort.send_keys("jamescharles12!")
browser.implicitly_wait(3)
browser.execute_script("window.open('http://www.google.de','new window')")
print("opened new tab")
try:
Recap = WebDriverWait(browser, 120).until(
EC.presence_of_element_located((By.ID, "paypalAccountData_addressSuggest"))
)
finally:
browser.forward()
print("ReCaptcha solved !")
print("Script goes on.")
browser.find_element_by_id("paypalAccountData_addressSuggest")
Adresse = browser.find_element_by_id("paypalAccountData_addressSuggest")
Adresse.click()
Adresse.send_keys("SW1A 1BD")
browser.find_element_by_id("paypalAccountData_address2")
Adresse2 = browser.find_element_by_id("paypalAccountData_address2")
Adresse2.click()
Adresse2.send_keys("Warwick House")
browser.find_element_by_id("paypalAccountData_address1")
ADL1 = browser.find_element_by_id("paypalAccountData_address1")
ADL1.click()
ADL1.send_keys("St. James's Palace")
browser.find_element_by_id("paypalAccountData_city")
City = browser.find_element_by_id("paypalAccountData_city")
City.click()
City.send_keys("London")
browser.find_element_by_id("paypalAccountData_phoneType")
Number = browser.find_element_by_id("paypalAccountData_phoneType")
Number.click()
browser.find_element_by_name("/paypalAccountData/phoneNumber")
Number1 = browser.find_element_by_id("/paypalAccountData/phoneNumber")
Number.click()
Number.send_keys("87536718921")
browser.find_element_by_id("paypalAccountData_dob")
DateOfBirth = browser.find_element_by_id("paypalAccountData_dob")
DateOfBirth.click()
DateOfBirth.send_keys("02041996")
browser.find_element_by_id("paypalAccountData_oneTouchCheckbox")
Checkout = browser.find_element_by_id("paypalAccountData_oneTouchCheckbox")
Checkout.click()
browser.find_element_by_id("paypalAccountData_marketingOptIn")
Checkout2 = browser.find_element_by_id("paypalAccountData_marketingOptIn")
Checkout2.click()
browser.find_element_by_id("paypalAccountData_tcpa")
Checkout3 = browser.find_element_by_id("paypalAccountData_tcpa")
Checkout3.click()
driver.get("https://www.paypal.com/welcome/signup?country.x=GB")
#get the window handle after the window has opened
window_before = driver.window_handles[0]
#open a new window
driver.execute_script("window.open('https://accounts.google.com/signup', 'new window')")
#get the window handle after a new window has opened
window_after = driver.window_handles[1]
#switch on to new child window
driver.switch_to.window(window_after)
#switch back to original window
driver.switch_to.window(window_before)
您可以执行这样的操作来在窗口之间切换。