0

I am trying to query text in within all option tags with data-store values labeled Book1. Below is the subject drop-down list.

<div class="form-group">
        <label>Cards</label>
        <select class="form-control giftcard-selector" name="giftcard">
                <option data-store="Book1" data-number="110" data-pin="333" data-balance="93.92" value="81372" style="display: none;">Book1: 1110 ($93.92)</option>
                <option data-store="Book2" data-number="111" data-pin="0619" data-balance="7.56" value="81371" style="display: none;">Book2: 112 ($7.56)</option>
                <option data-store="Book1" data-number="113" data-pin="8229" data-balance="10.24" value="81369" style="display: none;">Book1: 113 ($10.24)</option>
                <option data-store="Book2" data-number="114" data-pin="0984" data-balance="2.17" value="81373" style="display: none;">Book2: 115 ($2.17)</option>
        </select>
</div>

I have tried the following xpath to query all text within option tags data-store values labeled "Book1" but it returns "Null".Any help would be appreciated.

//select[@class="form-control giftcard-selector"]/option@data-store="Book1"

3 Answers 3

2

I think you built your xpath wrongly, try this:

For the elements:

//select[@class="form-control giftcard-selector"]/option[@data-store="Book1"]

For the text:

//select[@class="form-control giftcard-selector"]/option[@data-store="Book1"]/text()
Sign up to request clarification or add additional context in comments.

3 Comments

Correct! the attributes must be in brackets.
Hey Spencer the xpath you provided returns a syntax error. However when i use xpath = //select[@class="form-control giftcard-selector"]/option@data-store it returns the first attribute data-store value of book1 but not both data-store values of book1..
Can you show how are you using this locator in your question? Because it was not supposed to show syntax error, I tested this locator, paste the piece of your java code that uses it.
0

If you look at the <select> element closely, all the descendent <option> elements are having style attribute set as display: none;. So Selenium won't be able to locate them in a generic way.


Solution

Presumably, the texts within the <option> tags are also represented through a <ul> and a couple of <li> tags and you need to interact with the option elements through those tags.


Reference

You can find a couple of relevant detailed discussions in:

3 Comments

Hey Debajan, there are no <ul> or <li> tags in this script.
@SpaceTech Can you cross check once again for <span> tags?
@SpaceTech Search for //*[contains(., '1110')] and try to locate the other nodes.
0

You can use:

cssSelector: ".form-control.giftcard-selector option[data-number='1']"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.