对于不同的浏览器,xpath是否有所不同? [英] Is xpath is different for different browser?

查看:377
本文介绍了对于不同的浏览器,xpath是否有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常有趣的问题.我正在通过xpath获取值.

I am having a very funny issue. I am having a xpath through which i am retrieving value.

例如

System.out.print(driver.findElement(By.xpath("//*[@id='error-box']/ul/li")).getText().toString());

在firefox和Chrome中,它给出相同的文本,而在IE中,它给出不同的文本.

In firefox and Chrome it is giving same text while in IE it is giving different text.

各种浏览器的xpath之间是否有区别,还是我没有得到其他问题.

Is there any difference between xpath of various browser or it is some other issue which i am not getting.

推荐答案

阅读有关Selenium如何处理Xpath的信息此处.

Read up on how Selenium handles Xpaths here.

在Chrome和Firefox中,我右键单击了相同的DOM元素(如

In Chrome and Firefox, I right-clicked on the same DOM element (as described here), selected "copy Xpath" and this is what I got:

Chrome ://* [@@ id ="js-pjax-container"]/div 2 /form/button

Chrome: //*[@id="js-pjax-container"]/div2/div2/form/button

Firefox(带有Firebug):/html/body/div [4]/div 2 /div

Firefox (with Firebug): /html/body/div[4]/div2/div2/div2/form/button

(一个具有属性值,另一个(FF)是绝对路径,这表明FF无法理解Crhome生成的Xpath)

(one is with attribute value and the other (FF) is the absolute path, which demonstrates that FF doesn't understand Crhome generated Xpath)

因此,出于硒测试的目的,这在浏览器之间很重要. (我没有在IE上进行测试)

So for Selenium test purposes, it matters between browsers. (I didn't test on IE)

我跑了

 @Test
        public void testGitHubButton(){
        WebDriver driver = new FirefoxDriver();
        driver.get("https://github.com/");
       String signup = driver.findElement(By.xpath("/html/body/div[4]/div[1]/div[1]/div[1]/form/button")).getText();
           Assert.assertEquals("Testing for string equality", "Sign up for GitHub", signup );
        driver.close();
        driver.quit();
        }

测试通过.如果我在其中复制粘贴Chrome的Xpath,它将失败.

And the test passes. If I copy paste Chrome's Xpath in there, it will fail.

这篇关于对于不同的浏览器,xpath是否有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆