-1

here i want to fill the input field, but unable to access it by Xpath... Plz Help me out..

and the Code is below....

<table class="detailList" border="0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr>
            <td class="labelCol">
                <div id="div1">
                    <div class="pbSubsection">
                        <table class="detailList" border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                                <tr>
                                    <td class="data2Col" colspan="2">
                                        <span style="font-Size:12px;">
                                            Process Name
                                        </span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </td>

            <td style="text-align:left;" class="data2Col">
                <div id=div2">
                    <div class="pbSubsection">
                        <table class="detailList" border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                                <tr>
                                    <td class="data2Col" colspan="2">
                                        <div id="div3" class="requiredInput">
                                            <div id="div4" class="requiredBlock"></div>
                                            <input name="pName" style="width:50%;" type="text">
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </td>

        </tr>
    </tbody>
</table>

iam trying

WebElement ele = driver.findElement(By.xpath("//span[text()='Process Name']/preceding::td/div/input[@type='text']"));

ele.sendKeys("PM 001");

But here after preceding i know its wrong.. Plz Help me out with this.......

Here the name attribute value of input and div id's will change dynamically...

so iam trying to find by the label and preceding input tag...

Thanks in Advance

4

2 回答 2

1

您的 XPath 完全错误。

//span[normalize-space(text())='Process Name']/ancestor::tr/descendant::input

是你所追求的。

如果name那个input没有改变,你可以简单地通过以下方式获得它:

driver.findElement(By.name("pName"));

您的 XPath 在第一个障碍中失败,仅仅是因为“进程名称”周围span很多normalize-space空格,所以在比较之前强制它从文本中去除空格。

然后你也在下一站摔倒,preceding......你是span这里的'水平,你可以去的尽可能深,首先没有任何东西'先于'它。

于 2013-07-31T08:48:54.797 回答
0

//span[normalize-space()='进程名称']//ancestor::tr//div//input[@type='text']

于 2018-04-03T10:43:58.867 回答