得到“链接总数"的计数的差异.通过Selenium和浏览器开发工具访问网页 [英] Getting Difference in count of "Total Number of links" on webpage through Selenium and Browser Development Tools
问题描述
我写了一些代码来计算Web页面上的链接总数.我在硒中使用了JavascriptExecutor.但是问题是我在Selenium中获得了总数链接Java Script命令的不同计数,而在浏览器控制台中获得了相同的计数.以下是测试详细信息:
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:
正在测试的网站: https://www.ebay.com/ 测试:Ebay主页上的链接总数.
Website under test : https://www.ebay.com/ Test: Total number of links on Home Page of Ebay.
硒代码和结果:
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"));
结果:422
但是当我在浏览器控制台中执行相同操作时,我得到了440. 在此处输入图片描述
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
推荐答案
要回答您的问题非常困难,因为您没有提到在哪个浏览器控制台上执行了JavaScript
命令:
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
您通过 ChromeDriver
观察到的Test Result
与我通过 Chrome Development Console
观察到的快速测试结果完全相同,即 422 .请参见下面的快照:
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 :
但是,值得一提的是 IEDriverServer
和 GeckoDriver
都符合W3C标准和 Google Chrome
和 PhantomJS
仍然是 OSS兼容,从而通过不同的协议和标准来呈现 HTML DOM Tree
.尽管 DOM树呈现Mechanism
的差异可能微不足道,但是End Results
中的delta
差异足以失败您的Validation
.
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
.
因此,解决方案是始终选择任何单个变体( IE
/ Firefox
/ Chrome
/ WebDriver
/ Web Browser
组合的 PhantomJS
)以验证 Manual
和 Automated
Test Results
.
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
.
这篇关于得到“链接总数"的计数的差异.通过Selenium和浏览器开发工具访问网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!