Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Robot Framework Selenium中单击元素_Java_Selenium_Robotframework - Fatal编程技术网

Java 如何在Robot Framework Selenium中单击元素

Java 如何在Robot Framework Selenium中单击元素,java,selenium,robotframework,Java,Selenium,Robotframework,如何使用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&

如何使用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>
但我得到了一个错误:

登录测试
|失败| ValueError:带有前缀的元素定位器 'driver.findElement(By.Xpath(“//img[@src”)不受支持


如果您实际使用的是Robot Framework,那么为了使用所需的功能,您只需确保库已导入,然后使用所需的关键字

明确地说,在设置部分:

Library     Selenium2Library 
在测试用例或关键字中:

Selenium2library.Click Element    xpath=//img[contains(@src, 'profile.png')]
假设您的xpath是正确的。考虑到糟糕的定位器,通常您想要做的是将ID添加到您需要的东西中

Selenium2library.Click Element    xpath=//img[contains(@src, 'profile.png')]