0

我正在使用以下内容在文本框中输入文本:

driver.findElement(By.xpath("//input[@name = 'c_1']")).sendKeys("Test");

HTML:

<div id="ext-comp-1110" class=" x-panel criterion-block" style="width: 252px;">
<div id="ext-gen397" class="x-panel-bwrap">
    <div id="ext-gen398" class="x-panel-body x-panel-body-noheader" style="width: 252px;">
        <div id="ext-comp-1111" class=" x-panel criterion-label">
            <div id="ext-gen413" class="x-panel-bwrap">
                <div id="ext-gen414" class="x-panel-body x-panel-body-noheader">
                    <label id="ext-comp-1112">Insured Name contains:</label>
                </DIV>
            </DIV>
        </DIV>
        <input id="ext-gen186" class=" x-form-text x-form-field criterion " type="text" name="c_1" autocomplete="off" size="20" style="width: 222px;" title="">
    </DIV>
</DIV>

当我运行它时,我得到一个元素不可见的异常。

4

2 回答 2

0

它通常发生在元素被隐藏或被隐藏元素(如<div>. Selenium Webdriver 只有在它们可见时才能处理它。(我用 Javascript 做的 -> 参考链接)

看这里如何处理隐藏元素

于 2013-08-21T14:47:16.823 回答
0

尝试类似的东西;

driver.findElement(By.xpath("//div[@id='ext-comp-1112']/../../following-sibling::input"))

如果要使用标签文本;

driver.findElement(By.xpath("//div[text()='Insured Name contains:']/../../following-sibling::input"))

注意。我是凭记忆写的,所以它可能需要调整,但你应该明白

于 2013-08-22T10:11:22.337 回答