![](/img/trans.png)
[英]SELENIUM - How to count IWebElement in IList<IWebElement> and get the position in the list
[英]How to get Selenium IWebDriver and IWebElement from Coypu?
我最近开始使用Coypu通过Web浏览器自动执行某些任务。 它非常有用,尤其是在填写表格和导航链接时。
现在,我正在尝试使用表数据。 我实际上想获取表数据,并最终将其转储到以管道分隔的文本文件中。
但是,在Coypu和浏览表行和列时,我已经达到了自己的极限。 但是,有几个有关如何将表读入数据集合的示例。
一旦到达某个点,我想将Coypu对象带入Selenium对象中,以便可以完成表格工作,但是似乎无法从Coypu中删除它。
这是测试代码:Console.WriteLine(“ TestMethod1()”);
IWebDriver webDriver = null;
var sessionConfiguration = new SessionConfiguration()
{
Browser = Coypu.Drivers.Browser.Firefox,
AppHost = "http://blabla.com"
};
var browser = new BrowserSession(sessionConfiguration);
browser.Visit("/searches/index");
// Set the start date
browser.FillIn("sdate").With("01/01/2018");
// Set the end date
browser.FillIn("edate").With("12/30/2018");
// Set the city
browser.FindId("city").SelectOption("Chicago");
// Click on submit
browser.ClickButton("Submit");
// Get the table with data
var innerHTML = browser.FindCss("table#dataTable").InnerHTML;
Coypu.Drivers.Selenium.SeleniumWebDriver
//webDriver = (OpenQA.Selenium.IWebDriver)browser.Driver;
//IWebElement curTable = (IWebElement)browser.FindCss("table#dataTable").OuterHTML;
//TablePage page = new TablePage(webDriver);
//Utilities.ReadTable(page.Table);
Console.WriteLine( Utilities.ReadCell("Marker", 1) );
我的问题如下:
如何从Coypu BrowserSession中提取Selenium IWebDriver?
给定IBrowserSession browserSession
:
var nativeDriver = (OpenQA.Selenium.IWebDriver) browserSession.Driver.Native;
如何从Coypu中提取想要的表并将其设为Selenium IWebElement?
// Select your table via Coypu
var table = browser.FindCss ("table#dataTable");
// Cast ElementScope.Native to IWebElement
var nativeElement = (OpenQA.Selenium.IWebElement) table.Native;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.