Select dropdown list element

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mi1k
Posts: 1
Joined: 12 Apr 2017, 04:22

Select dropdown list element

12 Apr 2017, 04:40

Hi everyone, I want to select an element from a dropdown list.
For exemple, if I want to select france, I can do it the this way

<select name="centre" class="form-control" required="">
<option value="">Centres</option>
<option value="Edu2017-2017-02-23-04-43-43-577">Canada</option>
<option value="Edu2017-2017-03-22-04-59-51-627">USA</option>
<option value="Edu2017-2017-03-29-05-13-54-637">France</option>
</select>

Code: Select all

wb.Document.All.centre.selectedIndex := "3"
OR

Code: Select all

wb.Document.All.centre.Value := "Edu2017-2017-03-29-05-13-54-637"
But what I want to do, is to select a value based on the visible text in the dropdown list.
Sorry if my english is not clear.
User avatar
aztec3
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: Select dropdown list element

12 Apr 2017, 07:05

Update: Answered below.
Last edited by aztec3 on 12 Apr 2017, 09:37, edited 1 time in total.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Select dropdown list element

12 Apr 2017, 09:05

Try this:

Code: Select all

Loop % (opt:=wb.document.querySelector("select[name=""centre""]").options).length
{
	if ((pays:=(opt[a_index-1].innerText)) == "France")
		MsgBox, 64,, % "index " . (a_index-1) .  " - le nom du pays est: " .  pays
	else
		MsgBox, % "index " . (a_index-1) .  " - le nom du pays est: " .  pays
}

Hope this helps.

EDIT*:
Also next time clarify in the title of your post [Javascript] or something like that because all that follow the wb prefix fall under javascript.
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Draken and 153 guests