我想用selenium登录网站。 此站点有链接(成员登录),当我单击此链接时,会出现弹出窗口。在
网站URL是http://affiliates.888.com/
我写的代码如下。在
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
eight88 = webdriver.Chrome()
eight88.get("http://affiliates.888.com/")
assert "Earn Real Money" in eight88.title
loginForm = eight88.find_element_by_class_name("hide-under-480").click()
# so far popup appears.
eight88.switch_to_alert()
eight88.find_element_by_id("userName").send_keys("username")
eight88.find_element_by_id("password").send_keys("password")
当我运行这个脚本时,NoSuchElementException
发生。在
我不知道如何在弹出窗口中找到元素。在
我怎样才能登录这个网站弹出。在
授权表单位于
iframe
内,不是警报。为了能够处理iframe
内的元素,您应该首先切换到它:弹出窗口是由JavaScript生成的。所以这是一个动态页面。当你使用驱动程序。获取()您正在读取生成的第一个静态页面源代码,显然用户名和密码字段不包括在内。首先弄清楚JavaScript是如何调用弹出窗口的,然后使用selenium的exec函数执行该JavaScript,然后使用另一个函数对第一个结果进行身份验证。在
相关问题 更多 >
编程相关推荐