具有ID属性的元素不存在 [英] Element doesn't exist although it has ID attribute

查看:78
本文介绍了具有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

您可以在


tl;博士

在iframe下处理#document的方式


tl; dr

Ways to deal with #document under iframe

这篇关于具有ID属性的元素不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆