如何使用 Selenium 在 ExtJS 中单击元素? [英] How to click on elements in ExtJS using Selenium?

查看:18
本文介绍了如何使用 Selenium 在 ExtJS 中单击元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有两个元素(两个取消"元素).

取消

<div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left;" id="ext-gen2951">取消

如何点击第二个元素?显然,我不能给我们 id,因为它是在每次访问时随机生成的.我可以使用什么?

解决方案


1. 使用 FindElements 方法,该方法使用给定机制查找当前上下文中的所有 IWebElement.(在这种情况下,您始终需要知道要查找的元素的索引.)

IWebDriver driver = new FirefoxDriver();IListcancelDivs = driver.FindElements(By.XPath("//div[text()='Cancel']"));cancelDivs[1].click();//零基索引


2.如果那些取消按钮在不同的部分,可以通过非ExtJS id属性来识别.

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


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


3.如果那些取消按钮在不同的部分,可以通过不同的ExtJS类属性来识别.(使用有意义的)

<div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left;" id="ext-gen1179">取消</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">取消</div>


IWebElement secondCancelDiv = driver.FindElement(By.XPath("//div[@class='x-toolbar-right-row']//div[text()='Cancel']"));secondCancelDiv.Click();

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

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

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

How do I click on the second element? Obviously, I can't us id because it is randomly generated on each visit. What can I use?

解决方案


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();

这篇关于如何使用 Selenium 在 ExtJS 中单击元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆