Getting Difference in count of “Total Number of links” on webpage through Selenium and Browser Development Tools

我怕爱的太早我们不能终老 提交于 2019-12-24 17:53:22

问题


I have written code to count total number of link on Web Page. I used JavascriptExecutor in selenium of that. But issue is that I am getting different count for total number link Java Script command in Selenium and same in browser console. Here are testing details:

Website under test : https://www.ebay.com/ Test: Total number of links on Home Page of Ebay.

Selenium code and result:

WebDriver driver = new ChromeDriver();
    driver.get("https://www.ebay.com/");

    driver.manage().timeouts().implicitlyWait(20l, TimeUnit.SECONDS);

    JavascriptExecutor js = (JavascriptExecutor)driver;
    System.out.println(js.executeScript(" return document.links.length"));

Result : 422

But when I executed same in browser console then I am getting 440. enter image description here

I am unable to understand difference here. Please someone help me to understand


回答1:


It would be pretty tough to answer your question as you haven't mentioned on which browser console you executed the JavaScript command :

document.links.length

How ever the Test Result which you observe through ChromeDriver is just identical with my quick test result which I observe through Chrome Development Console i.e. the exact figure of 422. See the snapshot below :

However, it is worth to mention that IEDriverServer and GeckoDriver both being W3C Compliant and Google Chrome and PhantomJS still being OSS Compliant renders the HTML DOM Tree through different protocols and standards. Though the difference in DOM Tree rendering Mechanism can be insignificant but delta difference in the End Results is enough to FAIL your Validation.

Hence the solution would be to always choose any single variant (either of IE/Firefox/Chrome/PhantomJS) of WebDriver/Web Browser combination to validate for Manual and Automated Test Results.



来源:https://stackoverflow.com/questions/47955774/getting-difference-in-count-of-total-number-of-links-on-webpage-through-seleni

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!