如何处理xpath中文本节点中的括号?

时间:2012-09-14 06:02:30

标签: xpath textnode

假设我们有以下HTML代码

<label for="467578">AgendaShowCapacity (1 remaining)</label>

我尝试在Chrome中使用以下xpath表达式,但找不到该元素:

//label[text()='AgendaShowCapacity (1 remaining)']

我想知道是否应该责备括号。如果是的话,在这种情况下我该如何处理? 任何意见将不胜感激,谢谢!

编辑2012-9-18下面发布的实际代码块

<div id="pageContent">
    <fieldset>
        <legend>Agenda</legend>
        <ol class='fieldList custom' data-section='0'>
            <li class="checkboxLeft" data-id="467578" data-z="1">           
                <div class="fieldHolder1">
                    <input id="467578" type="checkbox" name="467578" />
                </div>
                <div class="fieldHolder2">
                    <label for="467578">AgendaShowCapacity&nbsp;(1 remaining)</label>
                </div>
            </li>
            <li class="checkboxLeft" data-id="467579" data-z="2">           
                <div class="fieldHolder1">
                    <input id="467579" type="checkbox" name="467579" />
                </div>
                <div class="fieldHolder2">
                    <label for="467579">AgendaHideReached</label>
                </div>
            </li>
            <li class="checkboxLeft" data-id="467580" data-z="3">           
                <div class="fieldHolder1">
                    <input id="467580" type="checkbox" name="467580" />
                </div>
                <div class="fieldHolder2">
                    <label for="467580">AgendaShowMessage</label>
                </div>
            </li>
            <li class="checkboxLeft" data-id="467584" data-z="4">           
                <div class="fieldHolder1">
                    <input id="467584" type="checkbox" name="467584" />
                </div>
                <div class="fieldHolder2">
                    <label for="467584">AgendaWaitlist</label>
                </div>
            </li>
        </ol>
    </fieldset>
    <div class="buttonGroup">
        <button type="button" name="ctl00$cph$ctlNavigation$btnAddAnother" class="button" onclick="SubmitForm(this);return false;">Add Another Person</button>
        <span class="textBetweenButtons">or</span>
        <button type="submit" name="ctl00$cph$ctlNavigation$btnContinue" class="button" onclick="SubmitForm(this);return false;">Continue</button>
    </div>
</div>

这是html页面的基本部分,我想在其中找到//标签元素。

第二次编辑2012/9/19 使用selenium-webdriver示例C#代码来定位该元素。

IWebDriver driver = new FirefoxDriver();
IWebElement = driver.FindElement(By.XPath("//div[@id='pageContent']//legend/following-sibling::ol/li/div/label[text()='AgendaShowCapacity (1 remaining)']"));
// Do something to that element

0 个答案:

没有答案