如何在 Selenium webdriver Python 中点击图像?
使用 click 方法可以在 Python 中使用 Selenium webdriver 点击图像。首先,我们必须借助 id、class、name、css、xpath 等任何定位符来识别图像。html 代码中的图像由 img 标签名表示。
让我们看看图像元素的 html 代码。

示例
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class ImageClk{
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver",
"C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//implicit wait
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//URL launch
driver.get("https://tutorialspoint.com/index.htm");
// identify image
WebElement l = driver.findElement(By.xpath("//img[@alt='Tutorialspoint']"));
String s = l.getAttribute("title");
System.out.println("Title attribute value is :" + s);
l.click();
driver.quit();
}
}输出

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP