使用SendKeys时,元素无法与Selenium Excel VBA交互 [英] Element not interactable with Selenium Excel VBA when using SendKeys
问题描述
我正在尝试登录网站,并且正在使用 FindElementById
。在下面的代码中,使用 SendKeys
的第一部分效果很好,但是当尝试对密码字段使用相同的技术时,我收到一条错误消息,告诉我该元素是不可交互
I am trying to login to a site and I am using FindElementById
. In the following code the first part of using SendKeys
works well but when trying to use the same technique for the password field, I get an error message which tells me that the element is not interactable
Sub Test()
Dim bot As New WebDriver
With bot
.AddArgument "--disable-notifications"
.Start "Chrome", "https://www.excelforum.com/excel-programming-vba-macros/"
.Get "/"
.FindElementById("navbar_username").SendKeys "username"
.FindElementById("navbar_password").SendKeys "password"
'.FindElementByName("vb_login_password").SendKeys "password"
Stop
End With
End Sub
推荐答案
您非常接近。具有 id 属性为 navbar_password
的 Password 字段具有以下属性:
You were pretty close. The Password field with id attribute as navbar_password
is having the property:
style="display: none;"
因此您将无法与该元素进行交互。
So you won't be able to interact with the element.
要将字符序列发送到用户名和密码 >字段,您可以使用以下任一定位器策略:
To send a character sequence both to the User Name and Password field you can use either of the following Locator Strategies:
-
使用
FindElementById()
:
.FindElementById("navbar_username").SendKeys "username"
.FindElementById("navbar_password_hint").SendKeys "password"
使用 FindElementByCss()
:
.FindElementByCss("input#navbar_username").SendKeys "username"
.FindElementByCss("input#navbar_password_hint").SendKeys "password"
使用 FindElementByXPath()
:
.FindElementByXPath("//input[@id='navbar_username']").SendKeys "username"
.FindElementByXPath("//input[@id='navbar_password_hint']").SendKeys "password"
您可以在以下地方找到一些有趣的讨论:
You can find a couple of revelant discussions in:
- Trying to fill text in input box with dynamic drop down
- Need help to fill number into Chrome input box with Selenium
这篇关于使用SendKeys时,元素无法与Selenium Excel VBA交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!