如何使用Selenium2Library为测试用例编写关键字,以单击没有元素ID的按钮?
以下是HTML代码.我是硒新手!
<a href="redirect.cfm?app=profile">
<div id="profile" class="icon">
<img style="display:block; margin:0 auto;" src="assets/images/profile.png">
<h3>Profile</h3>
</div>
</a>
我试过了
driver.findElement(By.Xpath("//img[@src='assets/images/profile.png']")).click();
但是得到了错误:
LoginTest
| FAIL | ValueError: Element locator with prefix
‘driver.findElement(By.Xpath(“//img[@ src’ is not supported
解决方法:
如果您实际使用的是Robot Framework,则只需使用确保已导入库的功能即可,然后使用所需的关键字.
明确地说,在“设置”部分中:
Library Selenium2Library
并在测试用例或关键字中:
Selenium2library.Click Element xpath=//img[contains(@src, 'profile.png')]
假设您的xpath是正确的.由于定位器不佳,通常您想要做的是将ID添加到所需的东西中.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。