具有ID属性的元素不存在 [英] Element doesn't exist although it has ID attribute
本文介绍了具有ID属性的元素不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在selenium excel vba中,我试图了解有关如何处理CSS选择器的更多信息 我想知道,因为在检查具有ID的元素并运行代码时,我收到一条消息,指出未找到该元素 这是到目前为止的代码
In selenium excel vba I am trying to learn more about how to deal with the CSS selectors And I am wondering because when inspecting an element with ID and when run the code I got a message that the element not found Here's the code till now
Private bot As New selenium.ChromeDriver
Sub Test()
Dim win, mainWin As selenium.Window, sCode As String, i As Long
Dim urlImage As String, urlPost As String
Dim sCase As String
sCase = "192160470"
Set bot = New ChromeDriver
With bot
.Start "Chrome"
'First Window (Main Window)
.Get "https://www.kuwaitcourts.gov.kw/searchPages/searchCases.jsp"
'.FindElementById("txtCaseNo").SendKeys sCase
.FindElementByCss("input[type=text][name='txtCaseNo']").SendKeys sCase
'MsgBox "Click OK After Entering Captcha", 64
Stop
.Quit
End With
End Sub
这是该元素的HTML部分
and here's the HTML part for that element
<td><input type="text" name="txtCaseNo" id="txtCaseNo" maxlength="9" class="inputTextBox" onkeypress="return onlyNumbers(event);"></td>
我被困在这一行
.FindElementByCss("input[type=text][name='txtCaseNo']").SendKeys sCase
感谢进阶的帮助或想法
推荐答案
要发送字符序列到 Username 字段,因为所需元素位于
To send a character sequence to the Username field as the the desired element are within an <iframe>
so you have to:
- 诱导 WebDriverWait 以使所需的框架可用并切换到.
- 诱导 WebDriverWait 以使所需的元素可点击.
-
您可以使用以下解决方案:
- Induce WebDriverWait for the desired frame to be available and switch to it.
- Induce WebDriverWait for the desired element to be clickable.
You can use the following solution:
With bot
.Start "Chrome"
.Get "https://www.kuwaitcourts.gov.kw/searchPages/searchCases.jsp"
.SwitchToFrame "searchCaseDiv"
.FindElementByCss("input[type=text][name='txtCaseNo']").SendKeys sCase
查看全文