使用Selenium Web驱动程序从网站获取隐藏文本值的Javascript [英] Javascript to get hidden text value from website using Selenium web driver

查看:93
本文介绍了使用Selenium Web驱动程序从网站获取隐藏文本值的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在字符串变量中获取此电话会议号码。

 < span itemprop =telephoneclass =hidden id =telefoon_28836_hidden> 010  -  79 53 364< / span> 

我在没有成功的情况下尝试了这段代码。

  JavascriptExecutor jse =(JavascriptExecutor)驱动程序; 
String script =return document.getElementByXPath('// span [@ itemprop ='telephone']')。getText();;
字符串telno1 =((JavascriptExecutor)驱动程序).executeScript(script).toString();

我收到String telno1行的这个例外



参数列表

请帮忙谢谢

解决方案

你可以使用这个,

  String theTextIWant =((JavascriptExecutor)驱动程序).executeScript(return arguments [0] .value;,driver.findElement(By.xpath(// span [@ itemprop ='telephone) ]))); 

您只需使用javascript来提取输入字段的value属性。如果它是div或textarea,那么您需要使用innerHTML,innerText或textContent属性。如下所示,

  String theTextIWant =((JavascriptExecutor)驱动程序).executeScript(return arguments [0] .innerHTML;, driver.findElement(By.xpath( //跨度[@ itemprop = '电话']))); 


How can i get this telefoon nummer in string variable.

<span itemprop="telephone" class="hidden" id="telefoon_28836_hidden">010 - 79 53 364</span>

I tried this code without ant success.

JavascriptExecutor jse = (JavascriptExecutor)driver;
 String script = "return   document.getElementByXPath('//span[@itemprop='telephone']').getText();";
 String telno1 = ((JavascriptExecutor) driver).executeScript(script).toString();

I am getting this exception for String telno1 line

ErrorHandler$UnknownServerException: missing ) after argument list

please any help thank you

解决方案

You can use this,

String theTextIWant = ((JavascriptExecutor) driver).executeScript("return arguments[0].value;",driver.findElement(By.xpath("//span[@itemprop='telephone']")));

You just use javascript to extract out the value attribute of the input field. If it were a div or textarea, then you'd like use the innerHTML, innerText, or textContent attributes. like below,

String theTextIWant = ((JavascriptExecutor) driver).executeScript("return arguments[0].innerHTML;",driver.findElement(By.xpath("//span[@itemprop='telephone']")));

这篇关于使用Selenium Web驱动程序从网站获取隐藏文本值的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆