How to click on elements in ExtJS using Selenium?

后端 未结 2 1707
北海茫月
北海茫月 2020-12-18 17:14

I have two elements on my page (two \'cancel\' elements).

相关标签:
2条回答
  • 2020-12-18 18:03


    1. Use FindElements method, which finds all IWebElements within the current context using the given mechanism. (In this case, you always need to know the index of the element you are looking for.)

    IWebDriver driver = new FirefoxDriver();
    IList<IWebElement> cancelDivs = driver.FindElements(By.XPath("//div[text()='Cancel']"));
    cancelDivs[1].click(); //zero-base index
    


    2. If those cancel buttons are in different sections, which can be identified by non-ExtJS id attributes.

    <div id='header'>
        <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen1179">Cancel</div>
    </div>
    <div id='footer'>
        <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen2951">Cancel</div>
    </div>
    


    IWebElement secondCancelDiv = driver.FindElement(By.XPath("//div[@id='footer']//div[text()='Cancel']"));
    secondCancelDiv.Click();
    


    3. If those cancel buttons are in different sections, which can be identified by different ExtJS class attributes. (use the meaningful ones)

    <div id='ext-gen1060' class='x-grid3-body'>
        <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen1179">Cancel</div>
    </div>
    <div id='ext-gen2555' class='x-toolbar-right-row'>
        <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen2951">Cancel</div>
    </div>
    


    IWebElement secondCancelDiv = driver.FindElement(By.XPath("//div[@class='x-toolbar-right-row']//div[text()='Cancel']"));
    secondCancelDiv.Click();
    
    0 讨论(0)
  • 2020-12-18 18:05

    If:

    1. there are always only 2 'Cancel' buttons on the page, and
    2. you always need the 2nd one,

    use //div[text()="Cancel"][2] xpath selector, or just find both of them and click the 2nd one.

    0 讨论(0)
提交回复
热议问题