<td colspan="2" align="center">
<img src="web/L001/images/IMAGENAME.jpg" width="213" height="46" border="0" onclick="javascript: MessageDisplay()" ></td>
This is the element I'm trying to click. My attempted code:
WebElement temp = driver.findElement(By.xpath("web/L001/images/Phishing_12.jpg"));
temp.click();
I even tried with the full address, but any ides would be appreciated.
I use this to log on to various websites but this particular one throws up a web-page before that I have to click on that element before I can continue. -Thx
We can click on an image with Selenium webdriver in Python using the method click. First of all, we have to identify the image with the help of any of the locators like id, class, name, css, xpath, and so on. An image in the html code is represented by the img tagname. Let us see the html code of an image element.
WebElement temp = driver. findElement(By. xpath("//img[contains(@src,'web/L001/images/IMAGENAME. jpg')]"));
We can check if an image is displayed on page with Selenium. To verify an image we shall take the help of Javascript Executor. We shall utilize executeScript method to execute the Javascript commands in Selenium. Then pass the command return arguments[0].
How to perform a Right Click in Selenium? For automating the right-click operation, Selenium provides a dedicated method – contextClick(). This method accepts the target WebElement as the argument. In order to use this method, use the Actions class object.
This xpath should find it
WebElement temp = driver.findElement(By.xpath("//img[@src='web/L001/images/IMAGENAME.jpg']"));
or use contains like so
WebElement temp = driver.findElement(By.xpath("//img[contains(@src,'web/L001/images/IMAGENAME.jpg')]"));
But i think the problem would be is that you are not wait
ing for the element.
Generally CSS selectors are favored over xpaths. That's why I would recommend:
WebElement temp = driver.findElement(By.cssSelector("img[src='web/L001/images/IMAGENAME.jpg']"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With