gpt4 book ai didi

c# - 如何从 Coypu 获取 Selenium IWebDriver 和 IWebElement?

转载 作者:太空宇宙 更新时间:2023-11-03 14:46:22 25 4
gpt4 key购买 nike

我最近开始使用 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?
  • 如何从 Coypu 中提取出我想要的表格并使其成为 Selenium IWebElement?

最佳答案

How do I extract the Selenium IWebDriver from Coypu BrowserSession?

给定一个 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;

关于c# - 如何从 Coypu 获取 Selenium IWebDriver 和 IWebElement?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53992094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com