简体   繁体   中英

How to get Selenium IWebDriver and IWebElement from Coypu?

I recently started using Coypu to automate some task with a Web Browser. It works great, especially when filling out forms and navigating links.

Now, I am attempting to work with the table data. I actually want to take the table data and eventually dump it to a pipe-separated text file.

However, I have reach my limitations with Coypu and navigating through table rows and columns. However, there are several examples of how to read tables into data collections.

Once I reach a certain point I want to take the Coypu objects and morph them into Selenium objects so that I can do the table work, but I can't seem to be able to get this out of Coypu.

Here is the test code: 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) );

My questions are the following:

  • How do I extract the Selenium IWebDriver from Coypu BrowserSession?
  • How do I extract out the table I want from Coypu and make it a Selenium IWebElement?

How do I extract the Selenium IWebDriver from Coypu BrowserSession?

Given an IBrowserSession browserSession :

var nativeDriver = (OpenQA.Selenium.IWebDriver) browserSession.Driver.Native;

How do I extract out the table I want from Coypu and make it a 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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