Selenium Log-in on Pop-up webpage without html

廉价感情. 提交于 2021-01-29 20:12:29

问题


In my Selenium program, I use a google-chrome driver to access and log into my account on this webpage. The problem is that the log-in webpage is a program with a pop-up window and without any HMTL code I can grab. Therefore I don't know how to type in my credentials. I have looked around and have seen several proposals with 'actions' like

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

But the problem is that it doesn't type in anything, it only places the cursor in the first field. I guess this is part of the security of the program, but by being able to place the cursor in the right place, I should be able to send keys to the driver and then move along with a tab command. But I don't know how.

Any help would be very appreciated. Thank you very much

For a reproducible example:

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 

Updated

As mentionned by Azy_Crw4282, the problem is here handling alerts, however the driver doesn't recognize any alert because for driver.switch_to_alert() I get the error:

  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

回答1:


Your code below is incorrect since it's not handling the prompt alert explicitly.

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

Change it as follows

actions.switchTo().alert().sendKeys("Username");
actions.switchTo().alert().sendKeys("Password");


来源:https://stackoverflow.com/questions/60496455/selenium-log-in-on-pop-up-webpage-without-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!