简体   繁体   中英

Selenium IDE If DIV contains Text click on the button

I try to click on <button> element that is child of <div> . The <div> also contains <span> element with certain text that I stored some steps before. I have lots of elements that have the structure below, but only one of them contains the exact text in the <span> . Based on the text in this <span> I want to click on the <button> above.

The structure of the 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.

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

Select previous element using jQuery selector only

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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