当动态生成Value属性时,如何在Selenium Web驱动程序中使用java从tag中获取值

我试图操作的 HTML
<select id="GlobalDateTimeDropDown" class="combo"
    onchange="CalculateGlobalDateTime('Time',this.value)" name="GlobalDateTimeDropDown">
       <option value="+5.5" selected="selected"> … </option>
       <option value="+12"> … </option>
       <option value="+8"> … </option>
       <option value="+2"> … </option>
    </select>
    <input id="GlobalDateTimeText" class="combo" type="text" name="GlobalDateTimeText"       value="" style="width:215px;padding:2px;" readonly="readonly"></input>

Java代码

WebElement values=driver.findElement(By.id("GlobalDateTimeText")).getAttribute("Value");
System.out.println(values);

输出
空白

解决方法

要选择输入值,您需要使用xpath选择器,因为使用by.id将找到select元素,因为它们共享相同的id – 这是不好的做法,因为它们确实应该是唯一的.无论如何,尝试:
driver.findElement(By.xpath("//input[@id='GlobalDateTimeText']")).getAttribute(‌​"value");

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些