简体   繁体   中英

Selenium X-path Selectors - I need to be able to select the different options in the drop down menu

I am new to automations.I have a drop down box with many available selections and want add automation but not sure how to add the with the selectors. I was able to get one selection working but want to add ' or the next selection", or the next depending on what the user selects. I hope that made sense, I am not sure If I need to CHAIN the selectors with OR statement or add some type of CHILD elements. All the possible selection in the drop down have the same class just different TEXT.

what's the best way to get all the possible dropdowns. I need it for the page object

This works but only selects one.. get SearchDate() { return $('//span[contains(text(),"Last 18 months")]'); }

Examples

<span class="form__select-custom-option    ">Last 7 days</span>
<span class="form__select-custom-option    ">Last 6 months</span>
<span class="form__select-custom-option    ">Last 30 Days</span>

However they all have a different data_test attribute Example of unique attribute for each

  data-test="date-range-1"
    data-test="date-range-2"
    data-test="date-range-3"
    data-test="date-range-5"

All the possible selection in the drop down have the same class just different TEXT.

Use the class attribute to get all of the <span> 's:

//span[normalize-space(@class)="form__select-custom-option"]

Or, if you want to use the data-test attribute, you can use

//span[contains(@data-test), "date-range-")]

You didn't provide the whole HTML source snippet, so this is kind of speculative.

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