0

I am working on a web-scraping project and have most of it working but have run into a problem clicking a single button. The problem is that the name and ID of the button in HTML are dynamically created:

<td colspan="1" rowspan="3" valign="middle"><input type="submit" name="11|2328342|429156$Link" value="Select" id="11|2328342|429156_Link" /></td>

and so, I can't use getElementById or getElementByClassName as the Id and name change with each iteration.

Is there any other way to reference and then click this button?

1
  • Have you tries using XPath? What do you use (selenium or IE or any other approach? Commented Jun 15, 2020 at 14:31

1 Answer 1

1

I am using selenium VBA. Have a look at this code (I have used CSS selector)

Private bot As New Selenium.ChromeDriver

Sub Test()
    With bot
        .Get "file:///C:\Sample.html"
        .FindElementByCss("input[value='Select']").Click
    End With
End Sub

As for the IE, you can use it like that

Sub Test()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True
        .Navigate2 "file:///C:/Sample.html"
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        .document.querySelector("input[value='Select']").Click
    End With
End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the responses. This is on a work PC so I am restricted to IE and can't use Selenium
Thanks Yasser but that code doesn't seem to work. I get an "Object doesn't support…" error on the .document.querySelector line
I don't know why it doesn't work for you. Can you provide a URL to have a look?
Hi Yasser. Sorry, the work URL on accessible from work PCs. I've been reading about querySelector and querySelectorAll. Apparently they return static and not 'live' object lists. I'm wondering whether that's why the .click method doesn't work?
I am not sure. Maybe it is related to javascript so it is dynamic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.