首页 > 解决方案 > c# selenium 通过部分关键字复制全文

问题描述

在我的 Selenium webdriver 中,我根据某个关键字搜索文本:

new WebDriverWait(driver, 
TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists((By.PartialLinkText(stringKeywords))));

我想获取我找到的全文并将其保存到一个字符串中。我怎么能做到这一点?我在某个地方找到了这个,但它不会让我将它用作字符串,因为它是一个 IWebElement。无论如何它可以帮助我吗?

IWebElement txtbox = driver.FindElement(By.PartialLinkText(stringKeywords));

标签: c#seleniumselenium-webdriverwebdrivergetattribute

解决方案


一旦您能够使用PartialLinkText定位 webelement ,要提取完整innerText内容,您可以使用GetAttribute()如下方法:

Console.WriteLine(driver.FindElement(By.PartialLinkText(stringKeywords)).GetAttribute("innerHTML"));

推荐阅读