Reputation: 27
I'm doing an automation bot for my website using vb.net I'm facing a problem with button click I have these 2 buttons
Button 1
<button type="submit" id="import_btn" class="btn btn-primary w-sm waves-effect waves-light"> Fetch </button>
button 2
<button type="submit" class="btn btn-primary waves-effect"> <span class="btn-label"><i class="fa fa-plus"></i></span>CREATE </button>
for automation I'm using this code:
For Each elem2 As HtmlElement In Webbrowser1.Document.GetElementsByTagName("button")
Dim valueArrtibute As String = elem2.GetAttribute("type")
If valueArrtibute = "submit" Then
elem2.InvokeMember("click")
End If
Next
I want to click button 2 but with my code is clicking both clicks
Upvotes: 0
Views: 38
Reputation: 18320
You could add a check for the button's InnerText
, which represents all text between the button's start and end tag (<button>
and </button>
).
If valueArrtibute = "submit" AndAlso elem2.InnerText.Contains("CREATE") Then
There are many ways to identify a specific element on a website. For more in-depth examples I recommend seeing my answer to this question: Is there a possibility to address elements on a website which have no ID?
Upvotes: 1