簡體   English   中英

Selenium 在沒有 HTML 的彈出式網頁上登錄

[英]Selenium log-in on pop-up webpage without HTML

在我的 Selenium 程序中,我使用 google-chrome 驅動程序訪問並登錄我在此網頁上的帳戶。 問題是登錄網頁是一個帶有彈出窗口的程序,沒有任何我可以抓取的 HTML 代碼。 因此我不知道如何輸入我的憑據。

我環顧四周,看到了幾個帶有“行動”的提案,例如

actions = ActionChains(driver)
actions.send_keys('skdkds')
actions.perform()

但問題是它沒有輸入任何內容,它只將光標放在第一個字段中。 我想這是程序安全性的一部分,但是通過將光標放在正確的位置,我應該能夠將密鑰發送給驅動程序,然后與選項卡命令一起移動。 但我不知道怎么做。

對於可重現的示例:

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");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM