I have this case where i cannot click the button.
It seems to be Span within span, how to use this on VBA?
<div class=" detail-section">
<span class="btn click-back">
<span> << Back to Fill</span>
</span>
<button class="btn click-primary">
<span>Create Detail</span>
</button>
</div>
i tried and it doesn't work
Obj.FindElement(By.XPath("//*[contains(#span, 'Create Detal')] ")).Click
I got the answer and working fine now.
Obj.FindElementByXPath("//button[#class ='btn click-primary']").Click
Related
I am using selenium to target 3 buttons as in the image below
Here is the code for each thumbnail
<div class="product">
<div class="product-image">
<img src="./images/raspberry.jpg" alt="Raspberry - 1/4 Kg">
</div>
<h4 class="product-name">Raspberry - 1/4 Kg</h4>
<p class="product-price">160</p>
<div class="stepper-input">
–
<input type="number" class="quantity" value="1">
+
</div>
<div class="product-action">
<button class="" type="button">ADD TO CART</button>
</div>
</div>
When I try the following code below it fulfills the goal of clicking the 3 buttons
add_cart_btn_locator = (By.CSS_SELECTOR, "div[class='product'] button")
add_cart_btn_link = driver.find_elements(*add_cart_btn_locator)
for i in add_cart_btn_link:
i.click()
But when I try to change my selector to div[class='product-action'] button, only the first button is clicked then the below error appears
Message: stale element reference: element is not attached to the page document
May I kindly ask what is the difference of the two locators and why they do not work identically?
change your loop :
add_cart_btn_locator = (By.CSS_SELECTOR, "div[class='product-action'] button")
add_cart_btn_link = driver.find_elements(*add_cart_btn_locator)
nbrlinks = len(add_cart_btn_link)
for i in range(nbrlinks):
add_cart_btn_locator = (By.CSS_SELECTOR, "div[class='product-action'] button")
add_cart_btn_link = driver.find_elements(*add_cart_btn_locator)
add_cart_btn_link[i].click()
you have to reload the search of items each time
I thought I could figure this out based on an excellent answer that Yu Zhou gave me in response to my previous question on this same topic [https://stackoverflow.com/questions/63677723/excel-ie-automation-identifying-a-css-element]
From the picture above what I'm trying to accomplish is to press the "Block & Lot" tab so that I can enter the search criteria into the proper fields and activate the search button to find it.
The code that I have so far is:
htmlDoc.getElementById("ext-comp-1072__ext-comp-1073").setAttribute "class", ""
' Next line selects the "Block & Lot" tab
htmlDoc.getElementById("ext-comp-1072__ext-comp-1079").setAttribute "class", "x-tab-strip-active"
' Next line hides the "Address/Borough" fields
htmlDoc.getElementById("ext-comp-1073").setAttribute "class", "x-panel x-panel-noborder x-hide-display"
Which gets me to the point where the "Block & Lot" tab is activated (or so I believe it is) but whatever I try I can't get the fields below ('select a borough', 'enter block' and 'enter lot') to appear so that I can enter data into them. The html code for this section of the website is below:
<div id="ext-comp-1071" style="left: 150px; bottom: 0px; position: absolute;">
<div class=" x-tab-panel search-tab" id="ext-comp-1072" style="width: 510px;">
<div class="x-tab-panel-header x-unselectable x-tab-panel-header-plain" id="ext-gen79" style="width: 510px;">
<div class="x-tab-strip-wrap" id="ext-gen82">
<ul class="x-tab-strip x-tab-strip-top" id="ext-gen84">
<li id="ext-comp-1072__ext-comp-1073">
<a class="x-tab-strip-close" id="ext-gen87"></a>
<a class="x-tab-right" id="ext-gen88" href="#">
<em class="x-tab-left">
<span class="x-tab-strip-inner">
<span class="x-tab-strip-text ">Address</span>
</span></em></a></li>
<li class="x-tab-strip-active" id="ext-comp-1072__ext-comp-1079">
<a class="x-tab-strip-close" id="ext-gen89"></a>
<a class="x-tab-right" id="ext-gen90" href="#">
<em class="x-tab-left">
<span class="x-tab-strip-inner">
<span class="x-tab-strip-text ">Block & Lot</span>
</span></em></a></li>
<li id="ext-comp-1072__ext-comp-1087">
<a class="x-tab-strip-close" id="ext-gen91"></a>
<a class="x-tab-right" id="ext-gen92" href="#">
<em class="x-tab-left">
<span class="x-tab-strip-inner">
<span class="x-tab-strip-text ">ZIP Code</span>
</span></em></a></li>
I can't click on an element in the screen, it's not a button but works like one. I have successfully located it through the web inspector (I think) but I can't figure out the reason of why isn't working... Previously in my code I used the same code for clicking in a "Log in" button and it worked perfectly. Here it is the code:
Set objCollection = IE.document.getelementsbytagname("div")
For Each elem In objCollection
If IsObject(IE.document.getElementsByClassName("btn-group")) Then 'Scratchpad button clicking
If IsObject(IE.document.getElementsByClassName("pull-left fang-button fang-button-subtle no-margin ng-binding")) Then
Debug.Print "found it"
elem.Click
Exit For
End If
End If
Next elem
I'm trying to click in the element "Scratchpad" at the top of the page, Thanks in advance!
HTML:
<div class="btn-group" role="group" style="border:1px solid #ccc"> <a ng-class="{'active': !CrossSegmentConfig.showScratchPad && !CrossSegmentConfig.showGraph}" class="pull-left fang-button fang-button-subtle no-margin ng-binding active" ng-click="CrossSegmentConfig.showScratchPad=false; CrossSegmentConfig.showGraph=false;" style=""> <i class="fa fa-align-left"></i> Parameters </a> <a ng-class="{'active': CrossSegmentConfig.showScratchPad}" class="pull-left fang-button fang-button-subtle no-margin ng-binding" ng-click="CrossSegmentConfig.toggleScratchPad()" style=""> <i class="fa fa fa-columns"></i> Scratchpad </a> <a ng-class="{'active': CrossSegmentConfig.showGraph}" class="pull-left fang-button fang-button-subtle no-margin ng-binding" ng-click="CrossSegmentConfig.toggleGraph()"> <i class="fa fa-line-chart"></i> Plot </a> </div>
It's an Angular JS directive. Try either of the following 2
ie.document.querySelector("[ng-click*=toggleScratchPad]").click
ie.document.parentWindow.execScript "document.querySelector('[ng-click*=toggleScratchPad]').click();"
I try to automate some manual processes by using VBA automation. One of them is to click on a element that has an empty content and at the moment I am not able to figure out how to deal with it
The HTML code that I am trying to click on:
<div id="searchcombobox-1077-triggerWrap" data-ref="triggerWrap" class="x-form-trigger-wrap x-form-trigger-wrap-toolbar">
<div id="searchcombobox-1077-inputWrap" data-ref="inputWrap" class="x-form-text-wrap x-form-text-wrap-toolbar">
<input id="searchcombobox-1077-inputEl" data-ref="inputEl" type="text" role="combobox" size="1" name="searchcombobox-1077-inputEl" placeholder="Account Number" tabindex="-1" class="x-form-field x-form-text x-form-text-toolbar " autocomplete="off" componentid="searchcombobox-1077">
</div>
<div id="searchcombobox-1077-trigger-picker" class="x-form-trigger x-form-trigger-toolbar x-form-search-trigger x-form-search-trigger-toolbar "></div>
</div>
The VBA code used is:
HTMLDoc.getElementById("searchcombobox-1077-inputEl").Value = '11xx111'
Set click_el = HTMLDoc.querySelector("#searchcombobox-1077-trigger-picker")
With click_el
.Focus
.FireEvent "onclick"
End With
What should be the approach that I need to take into consideration since the div element that I need to click on is empty?
Thanks,
Apologies if this question has been asked before . I have tried other solutions and they don't appear to work me. I am trying to use VBA to click on a search button but I get no response. The button HTML is as follows
<span id="searchButton">
<button class="btn btn-default" data-bind="click:
GetFilteredRequests.bind($data, 1)">
<span id="innerSeachButton" class="fa fa-search">
</span>Search
</button>
</span>
I was trying something like this but it doesn't work;
Dim e
For Each e In IE.document.getElementsByTagName("span")
If InStr(e.outerHTML, "btn btn-default") > 0 Then
Stop
e.Click
Exit For
End If
Next