尝试单击按钮 ID 时出现 Selenium 异常
我尝试将 Java Selenium 客户端与 JBehave 结合使用,与一个简单的网页进行交互,作为 BDD 技术的演示。
运行测试时,我尝试执行一个简单的
selenium.click("joinButton");
但我得到一个
(com.thoughtworks.selenium.SeleniumException: joinButton is not定义)
抛出异常。
我尝试过使用id=joinButton
将ID限定为dom ID,作为css选择器,甚至作为xpath,但无济于事。
该元素肯定会呈现在页面中。我显然在这里做了一些愚蠢的事情。
有什么指点吗?
谢谢
I'm attempting to use the Java Selenium client with JBehave to interact with a simple web page as a demonstration of BDD techniques.
When running the test, i'm trying to do a simple
selenium.click("joinButton");
but i'm getting a
(com.thoughtworks.selenium.SeleniumException: joinButton is not defined)
exception thrown.
I've tried qualifying the ID as a dom ID using id=joinButton
, as a css selector and even as xpath but to no avail.
The element is definitely rendered in the page. I'm clearly doing something daft here.
Any pointers?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
导航到 Selenium 中的页面后,您是否调用了
waitForPageToLoad()
?我敢打赌,当您调用click
时,您的 DOM 尚未加载。Did you call
waitForPageToLoad()
after navigating to the page in Selenium? I'm betting your DOM hasn't loaded yet when yourclick
is called.请确认在使用 xpath 和 css 进行验证时,您使用了
selenium.click("//[@id=joinButton]")
和selenium.click("css=#joinButton") 分别。
您还可以将
selenium.isElementPresent("joinButton")
保持在循环中,直到超时(30/60 秒),当 selenium 找到该元素时,它将跳出此循环并执行 click 命令。Please confirm that while verifying with xpath and css you used
selenium.click("//[@id=joinButton]")
andselenium.click("css=#joinButton")
respectively.You can also keep
selenium.isElementPresent("joinButton")
in a loop until some timeout (30/60 sec) and the moment selenium finds this element, it would come out of this loop and execute click command.我意识到问题出在这里。 Selenium 类正在被扩展,并且 click 方法被重写为只接受 CSS 选择器。现在,这个问题已被移除,操作将按预期进行。
感谢各位的帮助。
I realised what the issue was here. The Selenium class was being extended, and the click method overridden to only accept CSS selectors. With this cruft now removed, the operation works as expected.
Thanks for your help folks.