2 回答

TA贡献1835条经验 获得超7个赞
我刚刚修改了你的代码,现在它的工作原理:
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贡献1752条经验 获得超4个赞
在AUT中模拟动作时,还有其他事情需要注意。即微调器和装载机。所以你也需要处理这些。
在你的代码中引入。据观察,在单击“注册”按钮时,它开始显示加载程序,然后显示计划,以便处理下面的代码使用,直到该加载程序被隐藏,然后执行单击所需的计划。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()
在执行单击按钮时,它会重定向到新页面并显示新页面加载在那里,然后加载注册表单。使用下面的代码 -Free Plan
WebDriverWait(chrome, 10).until( EC.invisibility_of_element_located((By.ID, "pm_slow"))
注册表单中的用户名在 iframe 下加载,因此您需要先切换到 iframe,然后执行进一步的操作
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')
添加回答
举报