1

I am trying to fill out a form that has a drop down menu for each order number.

<select name="order(889673519).box(1).shippingmethod" onclick="" onchange="" 
id="order(889673519).box(1).shippingmethod"><option value="" 
id="order(889673519).box(1).shippingmethod.blank"></option>

for each drop down menu the number inside the name css selector will change, so the first one is 889673519 but the second one will be

<select name="order(889711159).box(1).shippingmethod" onclick="" onchange="" 
id="order(889711159).box(1).shippingmethod"><option value="" 
id="order(889711159).box(1).shippingmethod.blank"></option>

What path do I use to select multiple elements with different names, so I can iterate through them selecting my options.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ryan Bobber
  • 97
  • 1
  • 1
  • 6

2 Answers2

1

Use contains function:

elements = driver.find_elements_by_xpath("//select[contains(@name, 'order') and contains(@name, 'shippingmethod')]")
frianH
  • 7,295
  • 6
  • 20
  • 45
0

To identify the <select> nodes using the following Locator Strategies:

  • Using css_selector and id attribute:

    elems = driver.find_elements_by_css_selector("select[id^='order'][id*='box'][id$='shippingmethod']")
    
  • Using css_selector and name attribute:

    elems = driver.find_elements_by_css_selector("select[name^='order'][name*='box'][name$='shippingmethod']")
    
  • Using xpath and name / id attribute:

    elems = driver.find_elements_by_xpath("//select[starts-with(@name, 'order') and contains(@id, 'shippingmethod')]")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352