PlaywrightDriver 是一个基于 Playwright 的 WebDriver 实现,用于自动化 Web 浏览器。下面是一些 PlaywrightDriver 操作方式和相关案例代码:
打开浏览器 :
var browser = await PlaywrightDriver.CreateAsync();
导航到 URL:
var testResult = await browser.GoToPage(msgInfo, new PageActionArgs
{
Url = $"https://news.qq.com/",
OpenNewTab = true
});
定位元素:
var element = await browser.LocateElement(msgInfo, new ElementLocatingArgs
{
Selector = "input[placeholder='Search by invitation name']",
Highlight = true
});
输入文本:
testResult = await browser.ActionOnElement(msgInfo, new ElementLocatingArgs
{
Selector = "input[placeholder='Search by invitation name']",
Highlight = true
}, new ElementActionArgs(BroswerActionEnum.InputText, task.Content.Name));
点击元素:
testResult = await browser.ActionOnElement(msgInfo, new ElementLocatingArgs
{
Selector = "input[placeholder='Search by invitation name']",
Highlight = true
}, new ElementActionArgs(BroswerActionEnum.Click));