driver.findElement(By.xpath("xpath")).getCssValue("backgroundColor");
仅查找元素,不返回cssvalue。我还尝试了.isEnabled()
和.isDisplayed()
,只是看它是否可以工作,但同样发生。它只会找到元素,不会继续。
答案 0 :(得分:0)
尝试使用带硒的getCssValue的以下示例
public class Test123 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\xxxx\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver Driver = new ChromeDriver();
String baseURL = "http://www.google.com";
Driver.get(baseURL);
Driver.findElement(By.name("btnK"));
System.out.println("Color of a button before mouse hover: " + Driver.findElement(By.xpath(".//*[@id='tsf']/div[2]/div[3]/center/input[1]")).getCssValue("color"));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}