在没有 HTML 的情况下弹出网页上的 Selenium 登录
Selenium log-in on pop-up webpage without HTML
在我的 Selenium 程序中,我使用 google-chrome 驱动程序访问并登录我在 webpage 上的帐户。问题是登录网页是一个带有弹出窗口 window 并且没有任何我可以抓取的 HTML 代码的程序。因此我不知道如何输入我的凭据。
我环顾四周,看到了几个 'actions' 喜欢
的提案
actions = ActionChains(driver)
actions.send_keys('skdkds')
actions.perform()
但问题是它没有输入任何内容,它只将光标放在第一个字段中。我想这是程序安全性的一部分,但通过将光标放在正确的位置,我应该能够将密钥发送到驱动程序,然后使用 tab 命令移动。但是我不知道怎么办。
对于可重现的示例:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd
import datetime
import time
import glob
import os
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(link_mentionned_above) //then I am blocked
已更新
如 Azy_Crw4282 所述,问题在于处理警报,但驱动程序无法识别任何警报,因为 driver.switch_to_alert()
我收到错误:
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/alert.py", line 67, in text
return self.driver.execute(Command.W3C_GET_ALERT_TEXT)["value"]
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
您下面的代码不正确,因为它没有明确处理提示警报。
actions = ActionChains(driver)
actions.send_keys('skdkds')
actions.perform()
修改如下
actions.switchTo().alert().sendKeys("Username");
actions.switchTo().alert().sendKeys("Password");
在我的 Selenium 程序中,我使用 google-chrome 驱动程序访问并登录我在 webpage 上的帐户。问题是登录网页是一个带有弹出窗口 window 并且没有任何我可以抓取的 HTML 代码的程序。因此我不知道如何输入我的凭据。
我环顾四周,看到了几个 'actions' 喜欢
的提案actions = ActionChains(driver)
actions.send_keys('skdkds')
actions.perform()
但问题是它没有输入任何内容,它只将光标放在第一个字段中。我想这是程序安全性的一部分,但通过将光标放在正确的位置,我应该能够将密钥发送到驱动程序,然后使用 tab 命令移动。但是我不知道怎么办。
对于可重现的示例:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd
import datetime
import time
import glob
import os
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(link_mentionned_above) //then I am blocked
已更新
如 Azy_Crw4282 所述,问题在于处理警报,但驱动程序无法识别任何警报,因为 driver.switch_to_alert()
我收到错误:
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/alert.py", line 67, in text
return self.driver.execute(Command.W3C_GET_ALERT_TEXT)["value"]
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
您下面的代码不正确,因为它没有明确处理提示警报。
actions = ActionChains(driver)
actions.send_keys('skdkds')
actions.perform()
修改如下
actions.switchTo().alert().sendKeys("Username");
actions.switchTo().alert().sendKeys("Password");