selenium:未找到嵌套的 div 元素

发布于 2024-11-29 19:24:23 字数 190 浏览 1 评论 0原文

我对 selenium 有点陌生,并尝试使用 testng 和 eclipse 进行测试用例。我试图打开来自多个 ajax 调用的网页。有嵌套的 div 加载到表格内。一个 div 元素是一个搜索框。当我尝试使用测试用例输入搜索词时,它会出错“找不到元素”。我尝试了不同的方法来查找元素,但徒劳无功。我真的很感谢解决这个问题的方法。

谢谢, 〜萨拉特

I am kinda new to selenium and trying out test cases with testng with eclipse. The webpage i'm trying to open loads from multiple ajax calls. There are nested div's which load inside a table. one div element is a search box. When i'm trying to enter the search word using the test case it errors out 'element not found'. I tried out different ways of finding an element but in vain. I would really be thankful for ways to resolve this problem.

thanks,
~sharath

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以笙箫默 2024-12-06 19:24:23

我建议您使用 XPath,然后查找输入框就像将查询提交给 find_element_by_xpath 方法一样简单:“//input(@name='name')”

请参阅 W3school 了解完整的语法规范。

您可以使用一些工具来测试xpath,例如:Firebug。

我为此目的在我的博客上写了一篇文章。

I suggest that you use XPath and then finding an input box will be as simple as submitting this query to the find_element_by_xpath method: "//input(@name='name')"

Refer to W3school for complete syntax specification.

You could use some tools to test xpath, e.g.: Firebug.

I wrote an entry on my blog for this purpose.

情归归情 2024-12-06 19:24:23

如果不知道页面的结构等,就很难确切地知道发生了什么。

我可以建议的一件事是,在尝试使用它执行某些操作之前,您需要先等待所需的元素。

例如,您可以在尝试单击文本框等内容之前添加 waitForElementPresent 命令。

考虑一下:

<input type="text" id="mySearchBox" />

理想情况下,您需要 2 个命令:

waitForelementPresent : id=mySearchBox

然后

type : id=mySearchBox : Text To Search On

这些东西似乎很少包含在初始录制过程中。我经常必须进去并专门告诉 Selenium 等待某些元素。

Without knowing the structure of your page etc it's a little difficult to know exactly what's happening.

One thing I can sugest is that you do a wait for the element you require, before trying to do something with it.

For example, you may add a waitForElementPresent command before trying to click into something such as a text box.

Consider:

<input type="text" id="mySearchBox" />

Ideally you'll want to have 2 commands:

waitForelementPresent : id=mySearchBox

and then

type : id=mySearchBox : Text To Search On

These kinds of things rarely seem to be included as part of the initial recording process. I often have to go in and specifically tell Selenium to wait for certain elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文