在Selenium中,如何使用python在弹出窗口中登录网站?

尤里·科兹连科

我想使用 selenium 登录网站。这个网站有链接(会员登录),当我点击这个链接时,会出现弹出窗口。

网址为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发生。

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"userName"}
  (Session info: chrome=59.0.3071.115)
  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.4.0-83-generic x86_64)

我不知道如何去弹出窗口并在那里找到元素。

如何在弹出窗口中登录该网站。

安德森

授权表位于iframe,而不是警报内。为了能够处理内部元素,iframe您应该先切换到它:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait

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")
loginForm.click()

wait(eight88, 10).until(EC.frame_to_be_available_and_switch_to_it(eight.find_element_by_xpath('//iframe[contains(@src, "Auth/Login")]')))

eight88.find_element_by_id("userName").send_keys("username")
eight88.find_element_by_id("password").send_keys("password")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 Selenium 和 Python 在弹出窗口中登录

使用Selenium + Python通过弹出窗口登录

如何使用用户登录弹出窗口抓取网站

如何使用Selenium WebDriver处理“使用Google登录”弹出窗口

使用python关闭Selenium中的弹出窗口

使用 Selenium 关闭网站上的弹出窗口

如何在 Selenium Python 中使用 WebDriverWait 触发可点击元素后从弹出窗口中检索数据?

如何使用python“网络抓取”包含弹出窗口的网站?

如何使用python(Selenium)处理Selenium中的Windows身份验证弹出窗口(加Java)

如何使用 HTML CSS 在登录表单中创建弹出窗口?

如何使用 Selenium + Java 在 Google Chrome 弹出窗口中自动单击“允许”

无法在弹出窗口中单击 Selenium(python) 中的“接受所有”cookie

如何使用Selenium和Java处理电子商务网站https://www.firstcry.com中的弹出窗口

无法使用Selenium在Chrome浏览器中的权限弹出窗口中单击“允许”或“阻止”?

在使用Selenium VBA的弹出窗口中单击“确定”

使用 selenium webdriver 在弹出窗口中显示处理警报

如何在 Python Flask 网站上创建一个谷歌登录弹出窗口

如何从python的弹出窗口中关闭Tkinter主窗口?

如何在 selenium (Python) 中单击弹出窗口内的按钮?

如何使用 python selenium 打开弹出窗口 (PDF)

如何使用python selenium单击cookie弹出窗口

如何使用Selenium和python禁用Firefox中的文件下载弹出窗口?

如何使用Java处理Selenium WebDriver中的弹出窗口

设计登录/在弹出窗口中注册

如何在 selenium webdriver 中禁用“你想为这个网站保存密码”的 chrome 弹出窗口

使用 Selenium 抓取各种网站时如何处理 cookie 弹出窗口?

如何在 Python 中使用 selenium 登录网站?

如何使用 selenium python 登录到多个网站 url

如何使用 Selenium 和 Java 处理浏览器登录弹出窗口