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

次のようなものを試してください。

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 に答える
0

通常、要素が隠されているか、 のような非表示の要素によって囲まれている場合に発生し<div>ます。Selenium Webdriver は、それらが表示されている場合にのみ処理できます。(私はJavascriptでやった - >リンクを参照)

隠し要素の扱い方はこちら

于 2013-08-21T14:47:16.823 に答える