I'm currently stuck trying to click on buttons on a private website. The buttons I'm trying to click have the same attributes and I cannot distinguish which button I need to click. Here are the three buttons I'm trying to click. As you can see, they are similar and except for the text on the button. How can I select for specific button and click it?
<button ng-repeat="punch in $ctrl.nextPunches" ng-disabled="punch.sendingPunch || $ctrl.sendingPunch" type="button" class="btn btn-default ng-binding ng-scope" ng-click="$ctrl.addPunch(punch)" style="">
<!-- ngIf: punch.sendingPunch -->
Check In
</button>
===========================================================================
<button ng-repeat="punch in $ctrl.nextPunches" ng-disabled="punch.sendingPunch || $ctrl.sendingPunch" type="button" class="btn btn-default ng-binding ng-scope" ng-click="$ctrl.addPunch(punch)">
<!-- ngIf: punch.sendingPunch -->
Start Meal
</button>
==========================================================================
<button ng-repeat="punch in $ctrl.nextPunches" ng-disabled="punch.sendingPunch || $ctrl.sendingPunch" type="button" class="btn btn-default ng-binding ng-scope" ng-click="$ctrl.addPunch(punch)">
<!-- ngIf: punch.sendingPunch -->
Check Out
</button>
I have tried using this:
Set HTMLButtons = HTMLDoc.getElementsByTagName("button")
For Each HTMLbutton In HTMLButtons
Debug.Print HTMLbutton.getAttribute("ng-click"), HTMLbutton.getAttribute("type"), HTMLbutton.getAttribute("ng-repeat"), HTMLbutton.getAttribute("ng-disabled")
Next HTMLbutton
HTMLButtons(2).Click
However, the buttons that show up on the immediate window is not helpful and it doesn't click any button when I use the .Click command. These buttons are under the UI element on the webpage. I'm not sure if that is helpful but I can definitely provide more of the webpage code if needed.
Thanks!
You could use document.getElementsByClassName method or document.getElementsByTagName method to get the button (it will return an array), then, loop through this array and distinguish them based on the innerText property. More detail, you could check this article.
Besides, you could also add some custom attributes and set different value, then use it to distinguish them.
Related
I am trying to click on a button on a website using VBA Selenium via Chrome.
When I use VBA code to click the button, ElementNotVisibleError pops up:
VBA code:
Set CD = New Selenium.ChromeDriver
CD.Start
CD.Get Url
Application.Wait (Now + TimeValue("0:00:05"))
CD.FindElementByCss(".inline_cancel").Click
When I move the mouse to the place where button is, the button appears and HTML code style display changes to block and before it was none.
When set to "none" VBA cannot find the element.
When set to "block" VBA can detect the element.
HTML code:
<span class="edit-hover" style="display: none;"><input type="hidden" name="field_root_name" id="order_header_change_attachments_attributes__field_name" value="order_header_change[attachments_attributes][]" class="field_root_name"><input type="hidden" value="365995938" name="order_header_change[attachments_attributes][365995938][id]" id="order_header_change_attachments_attributes_365995938_id"><input value="false" class="delete-field" type="hidden" name="order_header_change[attachments_attributes][365995938][_delete]" id="order_header_change_attachments_attributes_365995938__delete"><span class="intent-field"><span class="attachment-intent-checkbox"><input name="order_header_change[attachments_attributes][365995938][intent]" type="hidden" value="Internal"><input class="intent_checkbox_field" id="attachment_365995938_intent" type="checkbox" value="Supplier" name="order_header_change[attachments_attributes][365995938][intent]">→ <label for="attachment_365995938_intent">Supplier</label></span></span><a aria-label="Delete Attachment" class="inline_cancel" href="javascript:void(0);" role="button" tabindex="0"> </a></span>
You saw it right. Clearly the desired element:
<a aria-label="Delete Attachment" class="inline_cancel" href="javascript:void(0);" role="button" tabindex="0"> </a>
have the ancestor <span> with attribute style="display: none;"
<span class="edit-hover" style="display: none;">
which implies the element is hidden i.e. either not visible or not enabled.
To click on the element you have make the desired element clickable by taking some actions on some other element first.
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
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?
How do I click on a web button that appears multiple times on a webpage? How do I click all of them?
I am testing the "Like" button on a website (Webstagram.com) that is meant for you to view and operate your Instagram page from your desktop.
20 different pictures are displayed on a page and each picture has its own "like" button assigned to it. I can't identify it by "like" and in the outerhtml there are different values for each one. How do I write a script to identify each one?
Here is some of the info on the properties/values.
class: btn btn-default btn-xs likeButton
htmlid: N/a
htmltag: Button
innerhtml: <I class="fa fa-heart"></I>Like
outterhtml (Like button for pic #1): <BUTTON class="btn btn-default btn-xs likeButton" type=button data-target="1194558981914665301_8054519"><I class="fa fa-heart"></I>Like</BUTTON>
outerhtml (like button for pic#2)
<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target="1194558967727891183_339837919"><I class="fa fa-heart"></I>Like</BUTTON>
NOTE I listed the outerhtml property values for two different pictures to show where the values differ. This is also the outerhtml code I tried to write to click on any like button and bypass any specific values:*
outerhtml: <BUTTON class="btn btn-default btn-xs likeButton" type=button data-target=".*_.*"><I class="fa fa-heart"></I>Like</BUTTON>
This is the script I tried to run that failed
1) systemutil.Run "websta.me/tag/graffiti";
2) Browser("#graffiti Instagram photos").Page("#graffiti Instagram photos").WebButton("<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target=".*.*"><I class="fa fa-heart"></I>Like</BUTTON> ").Click
3)wait(1)
4) Browser("#graffiti Instagram photos").Page("#graffiti Instagram photos").WebButton("<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target=".*.*"><I class="fa fa-heart"></I>Like</BUTTON> ").Click
5) wait(1)
repeat... –
Try something like this using Descriptive programming approach of QTP
Set oDesc = Description.Create
oDesc("micclass").value = "WebButton"
oDesc("html tag").value = "BUTTON"
oDesc("class").value = ".*likeButton"
odesc("class").RegularExpression = True
'Find all the Links
Set obj = Browser().Page().ChildObjects(oDesc)
Msgbox obj.Count 'will show how many buttons are found
For i = 0 to obj.Count - 1
Obj(i).Click
Wait 2 'waits for 2 sec
Next
You can use VRI (visual relations identifier) to link an ambiguous object (your like button) to a well defined object (the picture).
This way you can say "click the like button that's closes to picture X".
Another way is to create a simple web-extensibility project that exposes a new object for the pictures which support the functionality of Liking a picture.
I am automating an application with selenium.There are no normal labels like id,tag by which I will be able to find an element. So I was using the xpath[driver.findElement(By.xpath())]. But now i find that some of the xpaths of the WebElement changing dynamically while runtime and so my test cases are failing.Even the relative xpath option is not available for the HTML.I am pasting a part of the html of the AUT. Please let me know how to handle this scenario .
<div>
<button class="btn btn-primary ng-hide" ng-click="unlockOrder('/content/boss/en/dashboard');" ng-show="enableUnlockButton" type="button">Unlock Order</button>
<button class="btn btn-primary" ng-click="discardOrder('/content/boss/en/create-order/pre-order-options');" type="button">Discard Order</button>
<button class="btn btn-primary" ng-click="saveOrder(showSaveButton && ban_search.$valid);" ng-disabled="showSaveButton==false || ban_search.$invalid" type="button" disabled="disabled">Save Order</button>
</div>
I would rely on the button text:
driver.findElement(By.xpath('//button[. = "Unlock Order"]'))
where . refers to button's text.
Disclaimers first :
1) First question ever, I hope I'm doing this right, apologies if it's not the case.
2) English is not my native language, so sorry for any mistakes.
3) Made a search and couldn't find an answer.
Trying to explain in words will mean many words while a bootply can say it all :
http://www.bootply.com/EBIMFQ5jEC
Basically, what I want is almost working except for this : I would like that clicking on "title 3" for instance (after you've clicked on "title 1" or "title 2") hides the "first/second column(s)" so that the "third column" is the only one shown (and vice-versa of course). I hope this is clear.
I tried a few things with data-parent (such as this: http://www.bootply.com/pgoT2IPG8D which has data-parent="#collapse1" added for the first three buttons) but couldn't achieve anything...
Thanks in advance for any help !
To get what you want you will indeed have to set the `data-parent', but also notice that this also require a '.panel' class. From the docs:
If a selector is provided, then all collapsible elements under the
specified parent will be closed when this collapsible item is shown.
(similar to traditional accordion behavior - this is dependent on the
panel class)
demo: http://www.bootply.com/qhs4dQbFZK
So you should wrap you collapsible item in a .panel class (or change the plugin). See also: https://github.com/twbs/bootstrap/issues/15341
Then a collapsible item will look that shown below:
<div class="panel">
<div class="col-md-2 collapse" id="collapse1">
<div class="btn-group-vertical btn-block" data-toggle="buttons">
<button class="btn btn-default btn-lg" href="">First subtitle column</button>
<button type="button" class="btn btn-default btn-lg" data-toggle="collapse" href="#collapse1-1"><input type="radio" name="subtitle" id="st11">Subtitle 1-1</button>
<button type="button" class="btn btn-default btn-lg" data-toggle="collapse" href="#collapse1-2"><input type="radio" name="subtitle" id="st12">Subtitle 1-2</button>
<button type="button" class="btn btn-default btn-lg" data-toggle="collapse" href="#collapse1-3"><input type="radio" name="subtitle" id="st13">Subtitle 1-3</button>
</div>
</div>
</div>
Your button should get a data-parent attribute:
<button type="button" class="btn btn-default btn-lg" data-toggle="collapse" data-parent="#menurow" href="#collapse1"><input type="radio" name="title" id="title1">Title 1</button>
And your items should be wrapped inside the id set before (#menurow):
<div class="row" id="menurow"></div>
Notice that the .panel class also set some style rules, which should be overrules (undo) for your situation, for instance: .panel {margin-bottom: 0;}