简体   繁体   English

通过xpath名称查找元素时获取ElementNotVisibleException

[英]Get ElementNotVisibleException when find element by xpath name

I am using the below to enter a text in the text box: 我正在使用以下内容在文本框中输入文本:

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

HTML: 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>

When I run this I get a element not visible exception. 运行此命令时,出现一个元素不可见异常。

it normally happens when the element is hidden or is sourrounded by a hidden element like a <div> . 通常在元素被隐藏或被<div>类的隐藏元素包围时发生。 Selenium Webdriver can only handle it if they are visible. Selenium Webdriver仅在可见时才能处理。 (I did it with Javascript -> refer to the link) (我使用Javascript->参考链接)

look here how to handle hidden elements 看这里如何处理隐藏元素

Try something like; 尝试类似的东西;

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

if you want to use the label text; 如果要使用标签文字;

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

NB. 注意 I have written this from memory so it may need a tweak but you should get the idea 我是从内存中写出来的,因此可能需要调整,但是您应该明白

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM