Java 使用按钮的HTMlUnit驱动程序获取属性id
对于此HTML:Java 使用按钮的HTMlUnit驱动程序获取属性id,java,selenium,htmlunit-driver,Java,Selenium,Htmlunit Driver,对于此HTML: <ul class="listnav" id="yui_3_16_0_1_1496654440419_3201" role="presentation"> <li class="compose hasmultimsg primary-property-btn selected" id="Compose" role="presentation" data-fid="Compose"> <button tabindex="0" title="
<ul class="listnav" id="yui_3_16_0_1_1496654440419_3201" role="presentation">
<li class="compose hasmultimsg primary-property-btn selected" id="Compose" role="presentation" data-fid="Compose">
<button tabindex="0" title="Compose" class="btn btn-compose" id="yui_3_16_0_1_1496654440419_3200" data-action="compose">
<i></i>
<span class="icon-text" id="yui_3_16_0_1_1496654440419_3199">Compose</span>
</button>
</li>
</ul>
我的设置方法是:
@Before
public void setUp() throws Exception {
try {
if (driver != null)
driver.quit();
else {
driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
java.util.logging.Logger.getLogger("com.gargoylesoftware")
.setLevel(Level.OFF);
driver.manage().window().maximize();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
我正在使用以下配置:
视窗10
Selenium服务器单机版3.4.0
HTML驱动程序
我在控制台中看到以下输出:
文本为:撰写类为:btn btn撰写Id为:空标题为:
编写innerHTMLCompose
因此id属性的值为null,其他属性为OK
我不知道它为什么显示ID<代码> null 。
你能考虑更新我们的<代码> HTML 和<代码> HTMLUnter驱动程序< /代码>版本吗?感谢您使用Selenium独立服务器中包含的HTMLUnit驱动程序。我不知道这些站点使用的HTML版本是什么。您是否只有一个匹配的xpath节点?是的,我有。在我的控制台上也没有例外。@Before
public void setUp() throws Exception {
try {
if (driver != null)
driver.quit();
else {
driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
java.util.logging.Logger.getLogger("com.gargoylesoftware")
.setLevel(Level.OFF);
driver.manage().window().maximize();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}