下面是我试过的这个脚本。如何使用Xpath获取CSS颜色值?
- 如何使用此XPath识别元素并获取CSS颜色值?
这个Xpath是什么意思?
package mypackage; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; public class myclass { public static void main(String[] args) { String baseUrl = "http://newtours.demoaut.com/"; WebDriver driver = new FirefoxDriver(); driver.get(baseUrl); WebElement link_Home = driver.findElement(By.linkText("Home")); WebElement td_Home = driver .findElement(By .xpath("//html/body/div" + "/table/tbody/tr/td" + "/table/tbody/tr/td" + "/table/tbody/tr/td" + "/table/tbody/tr")); Actions builder = new Actions(driver); Action mouseOverHome = builder .moveToElement(link_Home) .build(); String bgColor = td_Home.getCssValue("background-color"); System.out.println("Before hover: " + bgColor); mouseOverHome.perform(); bgColor = td_Home.getCssValue("background-color"); System.out.println("After hover: " + bgColor); driver.quit(); } }
你能更具体地请问你到底想知道什么?因为,简单的谷歌搜索会告诉你所有关于xpath的信息。 – Subh 2014-11-22 11:40:23