VBA Selenium How select an option from dropdown list witthout select?

bionic

New Member
Joined
Apr 16, 2022
Messages
2
Office Version
  1. 2019
There is a site with this structure:

HTML:
<button _ngcontent-hpq-c150="" dropdowntoggle="" id="button-convert" type="button" aria-label="resul1" class="form-control dropdown-toggle" aria-haspopup="true" aria-expanded="false"> NAMEN <span _ngcontent-hpq-c150="" class="caret"></span></button>
<ul _ngcontent-hpq-c150="" id="resul1" role="menu" aria-labelledby="button3" class="dropdown-menu scrollable-menu" style="left: 0px; right: auto; display: none;">
<li _ngcontent-hpq-c150="" role="menuitem"><a _ngcontent-hpq-c150="" class="dropdown-item"> NAME1 </a></li>
<li _ngcontent-hpq-c150="" role="menuitem"><a _ngcontent-hpq-c150="" class="dropdown-item"> NAME2 </a></li>
   "
   "
<li _ngcontent-hpq-c150="" role="menuitem"><a _ngcontent-hpq-c150="" class="dropdown-item"> name179 </a></li>

the NAMEN field that appears on the button is the default name chosen in the options.
Explaining better: A button appears with a default name (NAMEN). When clicking on this button it shows me more names that when chosen will rename the original button and execute the necessary routine.
I can get the name in the options but I can't select it for the original button.

I can access the original button with:
HTML:
driver.FindElementByXPath("//button[@id='button-convert']").Click

And I can go to the new name line with:
Code:
text1=driver.FindElementByXPath("//ul[@id='resul1']/li[17]/a").Text
(on of 17 is the relative position in the list of names)
text1 has the desired new name to replace NAMEN

How can click in the chosen name to execute routine?

Any idea?
Thanks

The site is fot currency conversion: Banco Central do Brasil
 
Last edited by a moderator:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I found the solution:
driver.FindElementByXPath("//button[@id='button-convert']").Click
driver.FindElementByXPath("//ul[@id='resul1']/li[23]/a").ClickAndHold
driver.Wait 3000
driver.FindElementByXPath("//ul[@id='resul1']/li[23]/a").Click

Just included a ClickAndHold, wait 3s and another Click
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top