Selenium 硒化

Selenium 硒化,selenium,Selenium,只查找元素,不返回cssvalue。我还尝试了.isEnabled(),和.isDisplayed(),只是想看看它是否能工作,但同样的情况也会发生。它只找到元素,不继续执行。请尝试下面的示例,以获取包含selenium的getCssValue public class Test123 { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C


只查找元素,不返回cssvalue。我还尝试了
.isEnabled()
,和
.isDisplayed()
,只是想看看它是否能工作,但同样的情况也会发生。它只找到元素,不继续执行。

请尝试下面的示例,以获取包含selenium的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();
    }
    }
}

你的具体问题是什么?@cruisepandey你是对的。这里和评论一样。答案已被删除。-->从你糟糕的输入来看,我唯一能告诉你的是,背景色是错误的。它必须命名为背景色。如果这不起作用,您应该提供更多信息(html结构等)@mariamakilling使用相关的html更新问题您的示例如何帮助mariamakilling?你基本上也是这样做的。主要区别在于您使用的是By.name()而不是xpath()…@JosefBiehler:即使我们使用xpath,它也能工作。请使用xpath查找上面修改的解决方案。
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();
    }
    }
}