Selenium 2 /WebDriver 迁移问题 WebDriver 未选择正确的元素
我正在将我的测试套件从 Selenium 1 迁移到 WebDriver。我在单击包含美国可点击州地图的页面上的元素时遇到了问题。
使用 Selenium 1,我将执行以下操作以从地图中选择特定状态。
selenium.click("css=area[alt=North Carolina]");
在 Selenium 2 中,我将其转换为
driver.findElement(By.cssSelector("area[alt=North Carolina]")).click();
WebDriver 实际上选择了不同的状态。这不是时间问题,选择了一个状态,这只是不正确的状态。我尝试过将 cssselector 切换为 xpath ,结果相同。
不确定这是否与此问题相关
操作系统:Win XP
浏览器:在 IE 8 和 FF 5 上测试6
Selenium:2.5.0
页面代码示例
<area alt="California" shape="POLY" coords="10,60,29,68,25,98,56,146,51,167,17,138,3,70" href="javascript:LoadCategory('CA');">
I am in the process of migrating my test suite from the Selenium 1 to WebDriver. I've come across a problem clicking on elements on a page which contains a map of the USA clickable states.
Using Selenium 1 I would do the following to select a particular state from the map.
selenium.click("css=area[alt=North Carolina]");
In Selenium 2 I'm converting this to
driver.findElement(By.cssSelector("area[alt=North Carolina]")).click();
WebDriver actually selects a different State. This is not a timing issue, a state is selected it is just the incorrect state. I've tried switching out cssselector for xpath with the same result.
Not sure if this is related to this issue
OS : Win XP
Browsers: Tested on IE 8 and FF 5 & 6
Selenium : 2.5.0
Example of page code
<area alt="California" shape="POLY" coords="10,60,29,68,25,98,56,146,51,167,17,138,3,70" href="javascript:LoadCategory('CA');">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看您提供的页面的 HTML,似乎有针对 CA、AZ、OH 等州的单独页面。还有一些其他州(其中大多数)如 NM、MT 等都有公共页面。就 webdriver 而言,我不确定为什么它没有点击正确的元素。我写了类似下面的内容,对我有用。您必须将这个逻辑扩展到其他状态。
同样,您可以对具有单独页面的其他州执行此操作,例如
对于具有公共页面的州,
Looking at the HTML for the page you provided, it seems that there are individual pages for states like CA,AZ,OH etc. There are some other states (majority of them) like NM, MT etc all have common pages. As far as webdriver is concerned, I am not sure why it's not clicking on the right element. I wrote something like below that works for me. You will have to extend this logic for other states.
Similarly, you can do it for other states that have individual pages, like
For states that have common pages,
我建议使用 Javascript click() 方法。
例子,
I make a suggestion to use Javascript click() method.
example,