Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从文本框中获取特定文本_Javascript_Html_Selenium_Selenium Webdriver - Fatal编程技术网

Javascript 如何从文本框中获取特定文本

Javascript 如何从文本框中获取特定文本,javascript,html,selenium,selenium-webdriver,Javascript,Html,Selenium,Selenium Webdriver,我有一个场景,我需要从文本框中获取特定文本。我知道下面的代码将返回文本框中的全部文本。有没有办法从文本框中获取特定的文本行,而不是整个文本?谢谢 WebElement config = driver.findElement(By.id("adFragment")); //Assertion verifyDisplay(config.getAttribute("value"), By.id("adFragment")); HTML: <section style="displa

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

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>

标记源


请尝试以下方法,我还没有尝试过。但我想这会对你有帮助

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);  
}  

如果这对您有帮助,请告诉我。

getAttribute
将返回文本框中的全部文本。。。您能解释一下您需要从文本框中获取什么吗。@程序员,我需要获取一个动态变化的url链接作为字符串……您的问题不清楚。请仔细阅读并相应调整。您没有阅读我提供的链接。如果您只需要检索到的文本的一部分,则必须使用字符串函数对其进行切片。@familyGuy您的问题和注释仍然不清楚,那么您想要页面的URL还是文本框中的文本?