leochabi / selenium-vba

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

Finding element by partial id #27

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system : Win7
.Net Framework version : 2.0.7045
Office Version : 2003
SeleniumWrapper version : 1.0.11.0

Please could you provide sample VBA code, that will allow me to type in a field 
knowing only it's partial id.

For example:

  selenium.Type "id=OptionListControl__optionLeg4241e47e-1f84-48a3-b06e-9bcb766366e1__TextBoxNotional", "1500000"

Will not work because the middle 
"optionLeg4241e47e-1f84-48a3-b06e-9bcb766366e1" part is generated at random 

Pls could you provide universal code, I believe, using "contains" command?

Original issue reported on code.google.com by steepd...@gmail.com on 20 Aug 2013 at 5:51

GoogleCodeExporter commented 8 years ago
You can use a CSS selector :
[id^=start_string][id$=end_string]

With your example :
selenium.type "css=[id^=OptionListControl__optionLeg][id$=TextBoxNotional]", 
"1500000"

Some documentation about CSS selectors :
http://www.w3.org/TR/css3-selectors/

Original comment by florentbr on 20 Aug 2013 at 7:02

GoogleCodeExporter commented 8 years ago

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