硒-findElement

时间:2018-10-04 07:07:15

标签: selenium

enter image description here

driver.findElement(By.xpath("xpath")).getCssValue("backgroundColor");

仅查找元素,不返回cssvalue。我还尝试了.isEnabled().isDisplayed(),只是看它是否可以工作,但同样发生。它只会找到元素,不会继续。

1 个答案:

答案 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();
    }
    }
}