2 回答
TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊
我剛剛修改了你的代碼,現(xiàn)在它的工作原理:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
chrome = webdriver.Chrome(executable_path= 'C:\webdriver.exe\chromedriver.exe',port=9515)
url = 'https://protonmail.com/'
chrome.get(url)
chrome.implicitly_wait(10)
chrome.find_element_by_xpath('//*[@class="btn btn-default btn-short"]').click()
chrome.find_element_by_class_name("panel-heading").click()
chrome.find_element_by_id("freePlan").click()
time.sleep(10)
#chrome.find_element_by_xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "top", " " ))]')
chrome.switch_to.frame(chrome.find_element_by_xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "top", " " ))]'))
typeinput = chrome.find_element_by_xpath('//*[@id="username"]')
typeinput.click()
typeinput.clear()
typeinput.send_keys('password')
chrome.switch_to.default_content()
chrome.find_element_by_id("password").send_keys('password')
chrome.find_element_by_id("passwordc").send_keys('password')
TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊
在AUT中模擬動(dòng)作時(shí),還有其他事情需要注意。即微調(diào)器和裝載機(jī)。所以你也需要處理這些。
在你的代碼中引入。據(jù)觀察,在單擊“注冊(cè)”按鈕時(shí),它開(kāi)始顯示加載程序,然后顯示計(jì)劃,以便處理下面的代碼使用,直到該加載程序被隱藏,然后執(zhí)行單擊所需的計(jì)劃。ExplicitWait
chrome.find_element_by_xpath('//*[@class="btn btn-default btn-short"]').click()
WebDriverWait(chrome, 20).until(EC.invisibility_of_element_located((By.ID, "redir"))
chrome.find_element_by_css_selector("div[aria-controls='plan-free']").click()
在執(zhí)行單擊按鈕時(shí),它會(huì)重定向到新頁(yè)面并顯示新頁(yè)面加載在那里,然后加載注冊(cè)表單。使用下面的代碼 -Free Plan
WebDriverWait(chrome, 10).until( EC.invisibility_of_element_located((By.ID, "pm_slow"))
注冊(cè)表單中的用戶名在 iframe 下加載,因此您需要先切換到 iframe,然后執(zhí)行進(jìn)一步的操作
username_frame = chrome.find_element_by_xpath("//div[@class='usernameWrap']//iframe[@title='Registration form']")
chrome.switch_to.frame(username_frame)
WebDriverWait(chrome, 10).until( EC.visibility_of_element_located((By.ID, "username"))
chrome.find_element_by_id('username').send_keys(‘username’)
chrome.switch_to.default_content()
chrome.find_element_by_id("password").send_keys('password')
chrome.find_element_by_id("passwordc").send_keys('password')
添加回答
舉報(bào)
