Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
获取DIV的值,CSS值-WebDriver(selenium2)-JAVA_Java_Selenium_Webdriver - Fatal编程技术网

获取DIV的值,CSS值-WebDriver(selenium2)-JAVA

获取DIV的值,CSS值-WebDriver(selenium2)-JAVA,java,selenium,webdriver,Java,Selenium,Webdriver,嗨,我有这个html代码: <div id="idvalue" value="56"></div> 我正在使用Selenium 2 请提供帮助。值对于div元素无效。这不起作用,您不应该感到惊讶…value对于div元素来说不是有效的属性。这不起作用,你不应该感到惊讶…你试过这种方法吗 JavascriptExecutor js = (JavascriptExecutor)driver; Object val=js.executeScript("return docum

嗨,我有这个html代码:

<div id="idvalue" value="56"></div>
我正在使用Selenium 2
请提供帮助。

值对于
div
元素无效。这不起作用,您不应该感到惊讶…

value
对于
div
元素来说不是有效的属性。这不起作用,你不应该感到惊讶…

你试过这种方法吗

JavascriptExecutor js = (JavascriptExecutor)driver;
Object val=js.executeScript("return document.getElementById('idvalue').getAttribute('value');");

System.out.println("Value attr value: " + val);
输出:值属性值:56

您是否尝试过这种方法

JavascriptExecutor js = (JavascriptExecutor)driver;
Object val=js.executeScript("return document.getElementById('idvalue').getAttribute('value');");

System.out.println("Value attr value: " + val);

输出:Value attr Value:56

Try
System.out.println(driver.findElement(By.id(“idvalue”)).getText()。如果我有:
test
它返回“test”你确定你只有一个元素具有
id=“idvalue”
是的,我肯定。@LuisCarlos Try
System.out.println(driver.findelelement(By.id(“idvalue”).getCssValue(“value”)
Try
System.out.println(driver.findElement(By.id(“idvalue”)).getText())。如果我有:
test
它返回“test”你确定你只有一个元素具有
id=“idvalue”
是的,我肯定。@LuisCarlos Try
System.out.println(driver.findelelement(By.id(“idvalue”).getCssValue(“value”)是的,但好吧,他们需要从“数据-”开始。即使这样,我也不知道selenium2是否支持这一点……是的,但好吧,他们需要从“数据-”开始。即使这样,我也不知道selenium2是否支持……谢谢你的回复,但我发现我必须在另一个div中找到这个号码,就像这样:
56
,这很简单。谢谢你的回复,但我发现我必须在另一个div中找到这个号码:
56
,这很简单。