Find element which contains text

Zoran

Could someone please assist me in following issue: i have to pickup from dropdown elements which have - Open as a part of title (as per on screenshot below) enter image description here

Since that value will be change during time period, it is useless to use that, and have to pickup ones with 'Open' status (not showed, but rest of statuses are: Frozen & Closed) So, here is xpath which I tried:

//*[@id="period"]/contains(@text, '')

For above i got result from test is true. (It does exist text as I understand that) But when add wanted text

//*[@id="period"]/contains(@text, 'Open')

I got as a result false and can not find elements. Also, when searched with:

//*[@id="period"]

I got result (all periods are shown).

 01. Oct 2018 - 31. Oct 2018 - Open01. Sep 2018 - 30. Sep 2018 - Open01. Aug 2018 and so on ...

HTML is as follows:

<main class="main row">
<div class="content clearfix column medium-8">
<div class="row">
<article class="column medium-12">
<div class="t-box">
 <p></p><div class="compete">
 <a class="button primary" href="« Back to overview</a>
 <div class="promotion">
  <h2 class="promotion-header"><img src="/assets/images/system/stats/language/EN.png.pagespeed.ce.nTcGwJ7dzC.png">Top of the month</h2>

 <form class="row" method="GET" action="/compete">
 <input type="hidden" name="id" value="3">
 <div class="column large-2">
  <label for="period"><strong>&nbsp;<br>Period:</strong></label>
   </div>
   <div class="column large-8">
   <select id="period" name="period">
   <option value="39">01. Oct 2018 - 31. Oct 2018 - Open</option><option    value="38">01. Sep 2018 - 30. Sep 2018 - Open</option><option value="37">01. Aug 2018 - 31. Aug 2018 - Open</option><option value="36">01. Jul 2018 - 31. Jul 2018 - Open</option><option value="35">01. Jun 2018 - 30. Jun 2018 - Open</option><option value="34">01. May 2018 - 31. May 2018 - Open</option><option value="33">01. 

What I am doing wrong, please assist.

DebanjanB

To print all the months which have Open as a part of title you can use the following code block :

Select months = new Select(driver.findElement(By.id("period")));
List<WebElement> monthList = months.getOptions();
for(WebElement month:monthList)
    if(month.getAttribute("innerHTML").contains("Open"))
        System.out.println(month.getAttribute("innerHTML"));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find an element by Xpath which contains text

From Dev

Find an element that contains id of selector + text

From Dev

XPath: Find element that contains text X and not Y

From Dev

Python BeautifulSoup find element that contains text

From Dev

Find an element that contains id of selector + text

From Dev

How to find HTML element with a data attribute which contains a specific value?

From Dev

Create/append element containing blob text which contains quotes

From Dev

Python Selenium find element by link text contains a string with wildcard or regex

From Dev

Selenium: how to find element with with specific text without contains option

From Dev

if element contains text

From Dev

Select element if contains text

From Dev

Xpath to find out element which has ANY text

From Dev

Using $.contains to find if an element contains another with focus

From Dev

xpath: find element with attribute AND contains?

From Dev

Change style of an element which contains a specified word

From Dev

How to create a promise which contains a canvas element

From Dev

JavaScript find element by text

From Dev

Find element by text in tag

From Dev

Find which element is not sorted in a list

From Dev

Mongoid, find models which name contains string

From Java

Find all the persons which contains the provided resources

From Dev

Find files which does not contains selected string

From Dev

How to find which PPA contains a specific package?

From Dev

Find objects which contains subjects with given parameter

From Dev

find elements which id contains two substrings

From Dev

Cannot verify text which contains diacritics

From Dev

Scroll a Scroll View which contains Edit Text

From Dev

Cannot verify text which contains diacritics

From Dev

How to store the text of the row which contains the radiobutton 'on'?

Related Related

  1. 1

    Find an element by Xpath which contains text

  2. 2

    Find an element that contains id of selector + text

  3. 3

    XPath: Find element that contains text X and not Y

  4. 4

    Python BeautifulSoup find element that contains text

  5. 5

    Find an element that contains id of selector + text

  6. 6

    How to find HTML element with a data attribute which contains a specific value?

  7. 7

    Create/append element containing blob text which contains quotes

  8. 8

    Python Selenium find element by link text contains a string with wildcard or regex

  9. 9

    Selenium: how to find element with with specific text without contains option

  10. 10

    if element contains text

  11. 11

    Select element if contains text

  12. 12

    Xpath to find out element which has ANY text

  13. 13

    Using $.contains to find if an element contains another with focus

  14. 14

    xpath: find element with attribute AND contains?

  15. 15

    Change style of an element which contains a specified word

  16. 16

    How to create a promise which contains a canvas element

  17. 17

    JavaScript find element by text

  18. 18

    Find element by text in tag

  19. 19

    Find which element is not sorted in a list

  20. 20

    Mongoid, find models which name contains string

  21. 21

    Find all the persons which contains the provided resources

  22. 22

    Find files which does not contains selected string

  23. 23

    How to find which PPA contains a specific package?

  24. 24

    Find objects which contains subjects with given parameter

  25. 25

    find elements which id contains two substrings

  26. 26

    Cannot verify text which contains diacritics

  27. 27

    Scroll a Scroll View which contains Edit Text

  28. 28

    Cannot verify text which contains diacritics

  29. 29

    How to store the text of the row which contains the radiobutton 'on'?

HotTag

Archive