HTML:
<div class="dijitReset dijitValidationContainer">
<input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" type="text" role="presentation" readonly="readonly" tabindex="-1" value="Χ "/>
</div>
<div class="dijitReset dijitInputField dijitInputContainer">
<input id="ecm_widget_layout_NavigatorMainLayout_0_LoginPane_username" class="dijitReset dijitInputInner" type="text" name="ecm_widget_layout_NavigatorMainLayout_0_LoginPane_username" autocomplete="off" data-dojo-attach-point="textbox,focusNode" tabindex="0" aria-required="true" aria-invalid="false" value=""/>
由此我无法在dojo中找到使用xpath的用户名。
WebElement username = driver.findElement(By.xpath("//div[@class='dijitReset dijitInputField dijitInputContainer']//input[@id='ecm_widget_layout_NavigatorMainLayout_0_LoginPane_username']"));
注意:提到了autocomplete="off"
。
请你再描述一下。下面是我的HTML。
<div class="dijitReset dijitValidationContainer">
<div class="dijitReset dijitInputField dijitInputContainer">
<input id="ecm_widget_layout_NavigatorMainLayout_0_LoginPane_username" class="dijitReset dijitInputInner" type="text" name="ecm_widget_layout_NavigatorMainLayout_0_LoginPane_username" autocomplete="off" data-dojo-attach-point="textbox,focusNode" tabindex="0" aria-required="true" aria-invalid="false" value=""/>
我试过了(//input[contains(@id,'LoginPane_username'))
,但我收到了这个错误:
&#34;无法找到元素:&#34;
这个错误是由于autocomplete="off"
还是因为道场?
答案 0 :(得分:0)
您是否尝试直接使用以下ID
driver.findElement(By.id("ecm_widget_layout_NavigatorMainLayout_0_LoginPane_username"));
或使用前面的方法使用Xpath
//input[@id='ecm_widget_layout_NavigatorMainLayout_0_LoginPane_username']/preceding-sibling::div[@class='dijitReset dijitInputField dijitInputContainer']