blueprintmrk / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
0 stars 0 forks source link

How to select an option from a drop down #48

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Operating system : Win 7
.Net Framework version :
Office Version : 2010
SeleniumWrapper version : 2.39.0

What is your issue ?

Hello, I'm looking at selecting an option from a drop down and i didn't find 
how to select an option from the list with the value reference. Example, i 
would like to select "Valeur 2" with the value reference "value2". Please help 
me thanks :

<select name="select">
  <option value="value1">Valeur 1</option> 
  <option value="value2">Valeur 2</option>
  <option value="value3">Valeur 3</option>
</select>

Original issue reported on code.google.com by kong.fu...@gmail.com on 29 Jan 2014 at 11:01

GoogleCodeExporter commented 9 years ago
Selenium 1 example : driver.Select "css=#idselect", "label=Valeur 2"
Selenium 2 example : 
driver.findElementByCssSelector("oki").AsSelect.selectByText "Valeur 2"

Refer to the Api documentation for more information.

Original comment by florentbr on 29 Jan 2014 at 11:29

GoogleCodeExporter commented 9 years ago
THank you very much for answering me. 
I didn't understand what "oki" correspond to ?

Another question, if i want to use the first example, and put the content of a 
cell instead of the string "Valeur 2"

Like this : Selenium 1 example : driver.Select "css=#idselect", "label=" 
Workbook1.Sheets("Feuil1").Range("K1").Value 

But it's not working

Original comment by kong.fu...@gmail.com on 29 Jan 2014 at 1:46

GoogleCodeExporter commented 9 years ago
"oki" is an example of CSS selector which can be obtain with the recorder or by 
inspecting the source with Firebug.
This should work with your case :

 This one will select using the id value :
 Selenium 1 : driver.Select "name=select", "value=" & Workbook1.Sheets("Feuil1").Range("K1").Text
 Selenium 2 : driver.findElementByName("select").AsSelect.selectByValue Workbook1.Sheets("Feuil1").Range("K1").Text

 This one will select using the visible text :
 Selenium 1 : driver.Select "name=select", "label=" & Workbook1.Sheets("Feuil1").Range("K1").Text
 Selenium 2 : driver.findElementByName("select").AsSelect.selectByText Workbook1.Sheets("Feuil1").Range("K1").Text

Original comment by florentbr on 29 Jan 2014 at 2:23

GoogleCodeExporter commented 9 years ago

Original comment by florentbr on 8 Sep 2014 at 5:40