简体   繁体   English

在Selenium C#无头Chrome中提取表

[英]Extracting Table in Selenium C# Headless Chrome

I am doing automation of a site and I did all of it. 我正在做一个网站的自动化,我做了所有的事情。 At finally I am storing the table in List and it is working fine without headless Chrome. 最后,我将表存储在List中,并且在没有无头Chrome的情况下可以正常工作。 But when I changed my Chrome browser to "HEADLESS" I am getting empty "td" of table some of them showing and some of them is missing 但是,当我将Chrome浏览器更改为“ HEADLESS”时,表中的“ td”为空,其中某些显示,而某些丢失

ChromeOptions option = new ChromeOptions();
option.AddArgument("--headless");
IWebElement myTable = driver.FindElement(By.XPath("//*[@id=\"trades-view active\"]/table/tbody/tr[1]/td[5]"));

I am attaching both the Screen shots. 我同时附上了两个屏幕截图。 In first screen shot Location { X=666 , Y=1112 } and Locationonscreenoncescrolledintview { X=659 , Y= 512 } This is the case when I am getting the whole table without any problem. 在第一个屏幕快照中,位置{ X=666 , Y=1112 }和Locationonscreenoncescrolledintview { X=659 , Y= 512 }这种情况下,我可以毫无问题地获得整个桌子。 enter image description here 在此处输入图片说明

But when I want to change the browser in Headless state then I am getting Location { X=0 , Y=0 } and Locationonscreenoncescrolledintview { X=0 , Y= 0 } 但是,当我想以无头状态更改浏览器时,我得到的是位置{ X=0 , Y=0 }和Locationonscreenoncescrolledintview { X=0 , Y= 0 }

enter image description here 在此处输入图片说明

I shall be very thankful to you if you suggest me any changes to do it correctly. 如果您建议我做任何正确的更改,我将非常感谢您。

Thanks 谢谢

I think you may need to set the window size before navigate to the web. 我认为您可能需要在浏览网络之前设置窗口大小。

ChromeOptions option = new ChromeOptions();
option.AddArgument("--headless");
option.AddArgument("--window-size=2160,3840");
IWebElement myTable = driver.FindElement(By.XPath("//*[@id=\"trades-view active\"]/table/tbody/tr[1]/td[5]"));

Web application may display only some default content and show the remaining when users scroll to the position. 当用户滚动到该位置时,Web应用程序可能仅显示一些默认内容,并显示其余内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM