Selenium Element not corresponding to Click

midaste

New Member
Joined
Jan 16, 2025
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have the following element that is the 4th element on a nav bar within a website:

1737049964147.png


<a href="#step3" data-toggle="tab" data-bind="click: function(){ viewModel.GetRequiredDocuments(viewModel.xxxx); viewModel.xxxx(); }" aria-expanded="true">Documents</a>

I am able to select the element. I have confirmed that I have the right element by locals window in vba and debug print the label (ie Documents). However, when I send the "click", the website does not move to the proper tab.

It is not a wait until it is clickable problem as I have tried an explicit wait in which period I am to click on the element using the mouse (as a test).

Here is my relevant code:

Set documentLink = driver.FindElementByXPath("/html/body/div[11]/div[1]/div/ul/li[4]")
documentLink.Click

Any help is appreciated. Thanks.
 
index was outside the bounds of the array.
It's probably 1 instead of 0
driver.FindElementsByTag("li")(4).FindElementsByTag("a")(1).Click

If you open the website from a regular browser like Firefox, Chrome, Edge, etc., and open its Development Tools, what happens if you do this from the console tab?
document.getElementsByTagName("li")[3].getElementsByTagName("a")[0].click()

And how about this?
viewModel.GetRequiredDocuments(viewModel.xxxx)

I always try within a regular browser before using anything automated. If it works within the browser, it will most likely work with automation, the only difference is the syntax.
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
It's probably 1 instead of 0
driver.FindElementsByTag("li")(4).FindElementsByTag("a")(1).Click

If you open the website from a regular browser like Firefox, Chrome, Edge, etc., and open its Development Tools, what happens if you do this from the console tab?
document.getElementsByTagName("li")[3].getElementsByTagName("a")[0].click()

And how about this?
viewModel.GetRequiredDocuments(viewModel.xxxx)

I always try within a regular browser before using anything automated. If it works within the browser, it will most likely work with automation, the only difference is the syntax.

I don't think I can use the find elements by tag. The webpage has several hundreds of lines of code and I think it is picking up the wrong element when I find by tag instead of path. When I try this, I did a second version where I assigned it to a variable and looked in the locals window and it was wrong element. In the console, I don't know how to focus on the iframe like I do in VBA and therefore, it clicks on something in the sidebar. When I type the viewmodel line you asked about in the console, I get "Uncaught ReferenceError: viewModel is not defined at <anonymous>:1:1"
 
Upvote 0

Forum statistics

Threads
1,225,739
Messages
6,186,738
Members
453,369
Latest member
juliewar

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