c# - c# selenium 通过部分关键字复制全文
问题描述
在我的 Selenium webdriver 中,我根据某个关键字搜索文本:
new WebDriverWait(driver,
TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists((By.PartialLinkText(stringKeywords))));
我想获取我找到的全文并将其保存到一个字符串中。我怎么能做到这一点?我在某个地方找到了这个,但它不会让我将它用作字符串,因为它是一个 IWebElement。无论如何它可以帮助我吗?
IWebElement txtbox = driver.FindElement(By.PartialLinkText(stringKeywords));
解决方案
一旦您能够使用PartialLinkText定位 webelement ,要提取完整innerText
内容,您可以使用GetAttribute()
如下方法:
Console.WriteLine(driver.FindElement(By.PartialLinkText(stringKeywords)).GetAttribute("innerHTML"));
推荐阅读
- backup - 未找到 SQLLOGDIR 的变量
- android - 从 Uri 创建文件返回空文件
- c++ - 在 windows10 VS Code 上使用 CMake 对 imread 的 opencv 未定义引用
- selenium - c# - Selenium 3.14.0 + BrowserStack - Webdriver 异常 - 接收失败和实例化失败
- html - 如何使用 Vue 绑定/替换 HTML 中的现有数据
- algorithm - 找到相邻元素差值至少为 k 的最长递增子序列
- php - How to set money format in PhpSpreadSheet?
- asp.net-mvc - 如何从视图获取 HTML 下拉列表值到 MVC 中的控制器?
- php - 我无法弄清楚这段代码有什么问题
- html - 无法让页脚停留在页面底部