简体   繁体   English

Selenium IDE 如果 DIV 包含文本单击按钮

[英]Selenium IDE If DIV contains Text click on the button

I try to click on <button> element that is child of <div> .我尝试单击<div>子元素<button>元素。 The <div> also contains <span> element with certain text that I stored some steps before. <div>还包含带有某些文本的<span>元素,我之前存储了一些步骤。 I have lots of elements that have the structure below, but only one of them contains the exact text in the <span> .我有很多具有以下结构的元素,但其中只有一个包含<span>中的确切文本。 Based on the text in this <span> I want to click on the <button> above.基于此<span>的文本,我想单击上面的<button>

The structure of the HTML: HTML的结构:

<td>
  <div>
    <button> Click </button>
    <span> From ORI-1730 </span>
  </div>
</td>

I am selecting the span this way:我以这种方式选择跨度:

(css=span:contains("${SelectOrder}")) 

where "SelectOrder" == From ORI-1730.其中“SelectOrder” == 来自 ORI-1730。

And tried to select the button with:并尝试选择按钮:

(css=span:contains("${SelectOrder}").prev()) 

without success.没有成功。

I have found some themes, but was unable to make them work for me:我找到了一些主题,但无法让它们为我工作:

Jquery: Checking to see if div contains text, then action Jquery:检查 div 是否包含文本,然后操作

Select previous element using jQuery selector only 仅使用 jQuery 选择器选择上一个元素

您可以使用XPath而不是CSS来选择所需的按钮,如下所示:

xpath=//div[span[contains(text(), "${SelectOrder}")]]/button

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM