在 Selenium IDE 中单击包含部分 ID 和标题的 XPath 按钮 [英] Click a button with XPath containing partial id and title in Selenium IDE

查看:23
本文介绍了在 Selenium IDE 中单击包含部分 ID 和标题的 XPath 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Selenium IDE,我尝试使用 XPath 和元素的部分 ID 和标题单击网页上表格内的按钮.我使用的 XPath 是:

Using Selenium IDE, I'm trying to click a button within a table on a webpage using XPath with a partial id and a title from the element. The XPath I'm using is:

xpath=//*[contains(@id, 'ctl00_btnAircraftMapCell')]//*[contains(@title, 'Select Seat')] 

这就是我试图点击的按钮示例的整个 html 代码:

and thats the entire html code for an example of the buttons im trying to click:

<li id="ctl00_MainContent_repAircraftMap_ctl20_repAircraftMapRow‌​_ctl00_liAircraftMap‌​Cell" class=""> 
    <a id="ctl00_MainContent_repAircraftMap_ctl20_repAircraftMapRow‌​_ctl00_btnAircraftMa‌​pCell" href="javascript:void(0)" seatnumber="20A" mapbindattribute="1124" title="Select Seat 20A" onclick="SeatClick(1124);"></a> 
</li>

我是否错误地构建了这个?它不起作用!

Am I constructing this incorrectly? It's not working!

推荐答案

既然您已经提供了 HTML 示例,我们就可以看到您的 XPath 稍有错误.虽然它是有效的 XPath,但它逻辑上是错误的.

Now that you have provided your HTML sample, we're able to see that your XPath is slightly wrong. While it's valid XPath, it's logically wrong.

你有:

//*[contains(@id, 'ctl00_btnAircraftMapCell')]//*[contains(@title, 'Select Seat')]

翻译成:

为我获取所有具有包含 ctl00_btnAircraftMapCellID 的元素.从这些元素中,获取任何具有包含 Select Seattitle 的子元素.

Get me all the elements that have an ID that contains ctl00_btnAircraftMapCell. Out of these elements, get any child elements that have a title that contains Select Seat.

实际上想要的是:

//a[contains(@id, 'ctl00_btnAircraftMapCell') and contains(@title, 'Select Seat')]

翻译成:

获取我所有具有两者元素:一个包含ctl00_btnAircraftMapCell<的id/code> 和包含 Select Seattitle.

Get me all the anchor elements that have both: an id that contains ctl00_btnAircraftMapCell and a title that contains Select Seat.

这篇关于在 Selenium IDE 中单击包含部分 ID 和标题的 XPath 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆