2015-05-01 77 views
-2

我有一个场景,我需要从文本框中获取特定文本。我明白下面的代码将返回文本框中的整个文本。有没有办法从文本框中获取特定的文本行,而不是整个文本?谢谢!如何从文本框中获取特定文本

WebElement config = driver.findElement(By.id("adFragment")); 
//Assertion  
verifyDisplay(config.getAttribute("value"), By.id("adFragment")); 

的HTML:

<section style="display: block;"> 
     <div> 
      <h2 class="no-margin">tag source</h2> 
      <div> 
       <textarea placeholder="Your HTML fragment here" rows="30" id="adFragment" name="adFragment" style="height:400px; width:800px;"></textarea><br> 
      </div> 
     </div> 
    </section> 
+1

'getAttribute'将返回文本框中的整个文本...你能解释一下你需要从文本框中得到什么。 – Programmer

+0

@编程器,我需要获取一个动态变化的url链接作为一个字符串... – familyGuy

+0

你的问题还不清楚。请阅读此https://stackoverflow.com/help/mcve并相应地进行调整。 – SiKing

回答

1

请尝试以下,我还没有尝试过。但我认为它会帮助你

String eleValue = config.getAttribute("value"); 
if(eleValue.contains("YourRequiredText")){ 
    //Either you can put the required text in variable by splitting the string or mark it as pass 
    Assert.assertTrue(true); 
} 

让我知道这是否帮助你。

相关问题