【问题标题】:Copy full text by partial keyword c# seleniumc# selenium 通过部分关键字复制全文
【发布时间】:2019-12-27 12:02:22
【问题描述】:

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

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

我想获取我找到的全文并将其保存到一个字符串中。我怎么能做到这一点?我在某个地方找到了这个,但它不允许我将它用作字符串,因为它是一个 IWebElement。对我有帮助吗?

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

【问题讨论】:

    标签: c# selenium selenium-webdriver webdriver getattribute


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:
      string txt = driver.FindElement(By.PartialLinkText(stringKeywords)).Text;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-08
        • 1970-01-01
        • 1970-01-01
        • 2021-09-05
        • 1970-01-01
        相关资源
        最近更新 更多