猿问

如何在 selenium 中单击 img src - java

<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":"css

selector","selector":"a[src='webres_5acde3dbd3adc6.90334155/orangehrmLeavePlugin/images/ApplyLeave.png']"}"



神不在的星期二
浏览 354回答 2
2回答

梵蒂冈之花

你应该尝试<img>标签而不是<a>因为src是属性<img>CSSimg[src='/webres_5acde3dbd3adc6.90334155/orangehrmLeavePlugin/images/ApplyLeave.png']

开心每一天1111

但是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();
随时随地看视频慕课网APP

相关分类

Java
我要回答