简体   繁体   English

通过部分关键字复制全文 c# selenium

[英]Copy full text by partial keyword c# selenium

In my Selenium webdriver, I search for text based on a certain keyword:在我的 Selenium webdriver 中,我根据某个关键字搜索文本:

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

I would like to grab the full text I have found and save it into a string.我想获取我找到的全文并将其保存为字符串。 How would I be able to do this?我怎么能做到这一点? I found this somewhere, but it wont let me use it as a string because it is a IWebElement.我在某处找到了它,但它不允许我将它用作字符串,因为它是一个 IWebElement。 Could it help me anyway?它可以帮助我吗?

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

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

Console.WriteLine(driver.FindElement(By.PartialLinkText(stringKeywords)).GetAttribute("innerHTML"));
string txt = driver.FindElement(By.PartialLinkText(stringKeywords)).Text;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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