admin管理员组文章数量:1221428
Selenium has some nice support for finding elements in a page via xpath
selenium.isElementPresent("//textarea")
and in ajax pages you can use waitForCondition to wait on a page until something appears
selenium.waitForCondition("some_javascript_boolean_test_as_a_string", "5000")
My difficulty is, I can't seem to get into a position to use the xpath support for the boolean test. document.getElementById seems to work fine, but selenium.isElementPresent doesn't.
Is there any easy way of accessing selenium's xpath element finding abilities from within waitForCondition's first parameter?
Selenium has some nice support for finding elements in a page via xpath
selenium.isElementPresent("//textarea")
and in ajax pages you can use waitForCondition to wait on a page until something appears
selenium.waitForCondition("some_javascript_boolean_test_as_a_string", "5000")
My difficulty is, I can't seem to get into a position to use the xpath support for the boolean test. document.getElementById seems to work fine, but selenium.isElementPresent doesn't.
Is there any easy way of accessing selenium's xpath element finding abilities from within waitForCondition's first parameter?
Share Improve this question asked Jun 16, 2009 at 2:54 Matt SheppardMatt Sheppard 118k46 gold badges113 silver badges134 bronze badges 2- How are you running this script? Are you doing this from the Selenium IDE, or exporting it to another language (C#, Java, etc..) – Josh Commented Jun 16, 2009 at 3:13
- From Java - I had assumed it didn't matter as it all came down to the same JavaScript – Matt Sheppard Commented Jun 16, 2009 at 4:07
3 Answers
Reset to default 8An more straightforward way to do it is:
selenium.waitForCondition("selenium.isElementPresent(\"xpath=//*[@id='element_id_here']/ul\");", time_out_here);
You could do something like this:
selenium.waitForCondition(
"var x = selenium.browserbot.findElementOrNull('elementIdOrXPathExpression');"
+ "x != null && x.style.display == 'none';", "5000");
The waitForCondition just evaluates the last js expression result as a boolean, thereby allowing you to write complex tests (as shown here). For example, we're also using this technique to test whether jQuery AJAX has finished executing.
The only drawback is you're also now relying on the browserbot and the lower level core js API.
If you want to select an element by id, the simplest thing is to use straight selenese:
isElementPresent("textarea")
If you insist on using xpath you may have to use
isElementPresent("//*[@id='textarea']")
or
isElementPresent("//id('textarea')")
(The id function may not be cross-browser compatible)
If this does not help your html document may also have structural issues that is causing this to happen. Run an html validator like html validator to check for nesting problems and similar on your page.
本文标签: javascriptUsing selenium39s waitForCondition with an xpathStack Overflow
版权声明:本文标题:javascript - Using selenium's waitForCondition with an xpath - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739288299a2156571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论