testing - 如何单击按钮 "Submit Quote"它的 id ="div_5_1_1-lnk"在不同的应用程序页面中动态变化

标签 testing selenium selenium-webdriver

<div id="Form_Scope1" class="Form_Scope topLevel CoachView CoachView_show" data-eventid="" data-viewid="Form_Scope1" data-config="config1" data-bindingtype="" data-binding="" data-type="com.ibm.bpm.coach.Snapshot_a30ea40f_cb24_4729_a02e_25dc8e12dcab.Form_Scope">
<div id="Action_Group2" class="Action_Group topLevel CoachView CoachView_show" data-eventid="" data-viewid="Action_Group2" data-config="config9" data-bindingtype="" data-binding="" data-type="com.ibm.bpm.coach.Snapshot_a30ea40f_cb24_4729_a02e_25dc8e12dcab.Action_Group">
<div id="div_5_1" class="ContentBox" data-view-managed="true" style="display: none;"> </div>
<div class="s-action-group clearfix sticky">
<div class="l-nodeId" style="">QTO001_N002A</div>
<div class="p-action-group">
<div id="div_5_1_1" class="Action CoachView CoachView_show" data-eventid="boundaryEvent_7" data-viewid="Action3" data-config="config15" data-bindingtype="" data-binding="" data-type="com.ibm.bpm.coach.Snapshot_a30ea40f_cb24_4729_a02e_25dc8e12dcab.Action">
<button id="div_5_1_1-lnk" class="p-primary-btn btn btn-primary" type="button" title="" data-original-title="" style="background-color: rgb(56, 168, 182);">
<i class="icon-indent-right"></i>
<span>Submit quote</span>
</button>
<a href="#action" style="display: none;">
</div>

如何点击“提交报价”按钮 1.id="div_5_1_1-lnk"= 一页申请 2.id ="div_9_1_1-lnk"= 申请的另一页 在应用程序的不同页面中动态变化。 我已尝试按位置或相对路径使用 xpath 表达式,但它不起作用请告诉我还有其他可用的选项吗?

最佳答案

下面的选择器可以工作,

driver.findElement(By.cssSelector("div.Action button[id$='lnk']"));

这里的'$'表示按钮的id应该以'lnk'结尾。

  • The equals sign in attribute selectors may be prefaced by other characters which alter the meaning a bit.

  • Remember that classes and ID's are attributes too, and can be used with attribute selectors.

Refer this for more info.

关于testing - 如何单击按钮 "Submit Quote"它的 id ="div_5_1_1-lnk"在不同的应用程序页面中动态变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20882463/

相关文章:

c# - 如何根据 Arrange-Act-Assert 范式处理 nUnit 3 中的多个异常测试?

python - 单击不可见的元素(有 slider 的地方)

java - 如何在运行 Selenium 脚本时禁用 chrome 浏览器中的身份验证弹出窗口

firefox - Selenium webdriver 无法在 firefox 24.0 中使用 DOM 元素

selenium - 是否可以为 nwjs 应用程序编写自动化测试?

java - cucumber Selenium - Java - PageFactory : Step Definition: java. lang.NullPointerException

Java Webdriver HashMap 元素数组

unit-testing - 吊索测试用例SERVER端

Python:日期更改的单元测试

android - 在 Android : ProviderTestCase2 or RenamingDelegatingContext? 上测试数据库