<a href="/index.php/leave/assignLeave" target="_self" xpath="1"> <img src="/webres_5acde3dbd3adc6.90334155/orangehrmLeavePlugin/images/ApplyLeave.png" style=""></a>我收到一个错误:"no such element: Unable to locate element: {"method":"cssselector","selector":"a[src='webres_5acde3dbd3adc6.90334155/orangehrmLeavePlugin/images/ApplyLeave.png']"}"
2 回答
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
你应该尝试<img>
标签而不是<a>
因为src
是属性<img>
CSS
img[src='/webres_5acde3dbd3adc6.90334155/orangehrmLeavePlugin/images/ApplyLeave.png']
开心每一天1111
TA贡献1836条经验 获得超13个赞
但是src属性的值,即/webres_5acde3dbd3adc6.90334155/orangehrmLeavePlugin/images/ApplyLeave.png对我来说看起来是动态的。因此,您可以使用以下任一解决方案:
cssSelector
:driver.findElement(By.cssSelector("a[href*='assignLeave']>[src*='ApplyLeave']")).click();
xpath
:driver.findElement(By.xpath("//a[contains(@href,'assignLeave')]/img[contains(@src,'ApplyLeave')]")).click();
添加回答
举报
0/150
提交
取消