如何使用Python和Selenium自动登录一个据说不可见的元素?

时间:2022-03-12 19:24:32

I am currently writing a script and have succeded using selenium and python to open browser and navigate to the login screen on the website I will provide. But when I enter either of these 2 scripts, it doesn't work. It just says login not visible. Can someone tell me how I can do using Pythong and Selenium.

我目前正在编写脚本并成功使用selenium和python打开浏览器并导航到我将提供的网站上的登录屏幕。但是当我输入这两个脚本中的任何一个时,它都不起作用。它只是说登录不可见。有人可以告诉我如何使用Pythong和Selenium。

# fill in username
username = browser.find_element_by_id('id_username')
username.send_keys(usernameStr)
nextButton = browser.find_element_by_id('next')
nextButton.click()

and even used this one I found someone suggested

甚至用过这个我发现有人建议的

from selenium import webdriver
from selenium.webdriver.common import action_chains

driver = webdriver.Firefox()
driver.maximize_window()
driver.get("https://.com/auth/login/
")

action = action_chains.ActionChains(driver)

login = driver.find_element_by_class_name("login-icon")
login.click()

driver.switch_to.frame(driver.find_element_by_id('custlogin'))

username = driver.find_element_by_id('username')

action.move_to_element(username).perform()

username.send_keys('testeruser')

If someone could help me with this issue, I can go proceed on happily. Thank you for anyone that reads this.

如果有人可以帮我解决这个问题,我可以继续愉快地继续。感谢任何阅读此内容的人。

1 个解决方案

#1


0  

The Locator Strategy which you have used doesn't identifies the username field uniquely. The currect Locator Strategy identifies a hidden field. To identify the username and password field uniquely you can use the following lines of code :

您使用的定位器策略未唯一标识用户名字段。当前的定位策略识别隐藏的字段。要唯一标识用户名和密码字段,可以使用以下代码行:

username = browser.find_element_by_xpath("//fieldset[@class='fieldset_main']//input[@id='id_username']")
password = browser.find_element_by_xpath("//fieldset[@class='fieldset_main']//input[@id='id_password']")

#1


0  

The Locator Strategy which you have used doesn't identifies the username field uniquely. The currect Locator Strategy identifies a hidden field. To identify the username and password field uniquely you can use the following lines of code :

您使用的定位器策略未唯一标识用户名字段。当前的定位策略识别隐藏的字段。要唯一标识用户名和密码字段,可以使用以下代码行:

username = browser.find_element_by_xpath("//fieldset[@class='fieldset_main']//input[@id='id_username']")
password = browser.find_element_by_xpath("//fieldset[@class='fieldset_main']//input[@id='id_password']")