VBA click at element in IE - excel

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();"

Related

SEO help: Lists do not contain only <li> elements and script supporting elements (<script> and <template>)

Page Speed Insights is giving me the following error message for Accessibility:
Lists do not contain only li elements and script supporting elements (script and template)
Below are the code snippets that are generating this message. I'm not quite sure what needs to be done here to stop generating the errors, any advice would be much appreciated!
<ul class="slide_tit swiper-pagination-clickable swiper-pagination-bullets">
<li class="swiper-pagination-bullet" tabindex="0" role="button" aria-label="Go to slide 1">
<li class="swiper-pagination-bullet" tabindex="0" role="button" aria-label="Go to slide 2">
<li class="swiper-pagination-bullet" tabindex="0" role="button" aria-label="Go to slide 3">

VBA selenium <div button class span> tried to click click

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

Excel IE Automation Identify and act upon Tab Strip 'css' Element (encore)

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>

How can I use Selenium to click multiple plus buttons and show their entire content

I want to click and open multiple plus buttons and print out their texts. Here is the code that I have:
from selenium import webdriver
chrome_path=r"G:\My Drive\chrome_driver\chromedriver_win32\chromedriver.exe"
driver=webdriver.Chrome(chrome_path)
driver.get('https://meshb.nlm.nih.gov/treeView')
for links in driver.find_elements_by_css_selector('a.ng-scope'):
links.find_element_by_xpath("following-sibling::span").click();
for sublinks in links.find_elements_by_xpath("//*[#class='ng-scope']/span"):
print(sublinks.text)
here is what I see! the nodes' text is duplicated! and the code cannot open all the plus buttons. Only the first level plus buttons are opened, how can I change my code to be able to open all plus buttons, and once every plus button is open, I see the node'stext along with the whole content that is associated with it?
A part of html looks like this:
<a class="ng-scope">
<span class="ng-binding ng-scope">Anatomy [A]</span>
</a>
<ul class="treeItem ng-scope">
<li class ="ng-scope" >
< a class ="ng-scope" href="/record/ui?ui=D001829" >
< span class ="ng-binding ng-scope" > Body Regions[A01] < / span >
</a>
</li>
< li class ="ng-scope" >
<a class ="ng-scope" href="/record/ui?ui=D001829" >
< span class ="ng-binding ng-scope" > Cardio Vascular< / span >
</a>
<ul class="treeItem ng-scope">
<li class="ng-scope">
<a class="ng-scope" href="/record/ui?ui=D015824">
<span class="ng-binding ng-scope">Blood-Air Barrier [A07.025]</span>
</a>
<ul class="treeItem ng-scope">
<li class="ng-scope">
<a class="ng-scope" href="/record/ui?ui=D018916">
<span class="ng-binding ng-scope">Blood-Aqueous Barrier [A07.030]</span>
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>

jQuery UI Tabs Widget and Nested list

I have following nested tabs that I want to show in
<div id="1">
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
<div id="a">
<div id="aa1h">
Sub Tab AA1 Header
</div>
<div id="aa1c">
Sub Tab AA1 Content
</div>
<div id="aa2h">
Sub Tab AA2 Header
</div>
<div id="aa2c">
Sub Tab AA2 Content
</div>
</div>
</div>
$('#1').tabs();
Now I want to display three tabs using jQuery tabs or YUI tabview as following:
First tab displays #a (the whole thing)
Second tab displays #aa1c (only content for aa1)
Third tab displays #aa2c (only content for aa2)
I am having some problems with this method, any help is appreciated.
http://jsfiddle.net/RQcwE/1/
See above example for my problem.
UPDATE:
With help from Hanlet EscaƱo I have achieved what I wanted with couple of blank divs and some jQuery Code..
http://jsfiddle.net/RQcwE/3/
This is an example with sub-tabs that might work for you:
<div id="1">
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
<div id="a">
<ul>
<li>Sub A 1</li>
<li>Sub A 2</li>
</ul>
<div id="aa1">
Sub Tab A content 1
</div>
<div id="aa2">
Sub Tab A content 2
</div>
</div>
<div id="b">
<ul>
<li>Sub B 1</li>
<li>Sub B 2</li>
</ul>
<div id="bb1">
Sub Tab B content 1
</div>
<div id="bb2">
Sub Tab B content 2
</div>
</div>
<div id="c">
<ul>
<li>Sub C 1</li>
<li>Sub C 2</li>
</ul>
<div id="cc1">
Sub Tab C content 1
</div>
<div id="cc2">
Sub Tab C content 2
</div>
</div>
</div>
you just build them like this:
$("#1" ).tabs();
$("#a" ).tabs();
$("#b" ).tabs();
$("#c" ).tabs();
JSFiddle: http://jsfiddle.net/p84kC/

Resources