在 chrome 中我得到一个 xpath 值:
//*[@id='user_change_pw_form']/div[3]/span
对于萤火虫中的相同元素,我得到:
/html/body/div[2]/form/div[3]/span
为什么我必须分离这样的 xpath 查询才能在 Selenium 测试用例中获得一个相同的元素:
switch (System.getProperty("test.driver"))
{
case "chrome":
case "html":
text = driver.findElement(By.xpath("//*[@id='user_change_pw_form']/div[3]/span")).getText();
case "gecko":
text = driver.findElement(By.xpath("/html/body/div[2]/form/div[3]/span")).getText();
break;
}
虽然相应的对应物给出了错误的浏览器“无法定位元素”,但两个 xpath 查询在两个浏览器控制台中都有效。
提前致谢!