iMacros - TAG specific element with XPATH - html

and thank you in advance for taking a minute of your valuable time to solve this puzzle and educate me on the topic.
(please forgive my terminology)
I am using the following code in iMacros for Firefox to select an element on the site, which works fine, as long as the element exists and is in the same order.
TAG XPATH=".//*[#id='contacts']/ul/li[1]/div/ul/li[1]" EXTRACT=TXT
Which in this case would result in "New York, NY"
From:
<div id="contacts" class="article expanding_group">
<div class="article-header">
<!-- Public Company = Block. Public Name/Title = Restricted. -->
<ul class="list">
<li class="list_item">
<div class="list_item_content contact-detail">
<div class="edit expanded">
<ul>
<li class="name"> New York, NY </li>
<li class=" ellipsis">
http://www.a24films.com
</li>
<li class="info ">
+1 646 568 6015
<span class="attributes">phone</span>
</li>
<li class="info ellipsis">
info#a24films.com
</li>
<li class="address ">601 West 26th Street</li>
<li class="address ">Suite 1740</li>
<li class="address "> New York, NY 10001 </li>
<li class="address ">USA</li>
<li class="address ">
</ul>
</div>
However, if the field is missing, it will skip to the next field which will, in essence, result in data being inserted into the incorrect row.
E.g. if I am expecting columns "name, phone, address", and it is missing phone, it will result in "name, address, blank".
I can see it I want only when list item 1's class="name", so my question is: is there a way to specify that I want the list item number 1 that contains "name" in class?
I have tried a variation of strings to no avail, but I woulf imaging something like this is possible:
TAG XPATH=".//*[#id='contacts']/ul/li[1]/div/ul/li[1]/name" EXTRACT=TXT
Thank you for your time,
Reinaldo

You can try the following code:
TAG XPATH=".//*[#id='contacts']/ul/li[1]/div/ul/li[#class='name'][1]" EXTRACT=TXT

Try this Xpath:
.//*[#id='contacts']//li[#class='name'][1]
I don't think #Shugar's code will work.

Related

How to force the first option in SORT BY to show the selected mark?

<a class="mobileSortBy-toggle_new"
data-collapsible="mobileSortBy-panel-{{type}}"
data-collapsible-disabled-breakpoint="medium"
data-collapsible-disabled-state="closed"
data-group-collapsible="main">{{lang 'common.sorter.sort_by'}}</a>
<div class="mobileSortBy-panel" id="mobileSortBy-panel-{{type}}" data-mobile-sort-by>
<h4 class="mobile-panel-heading"><span class="mobile-panel-heading-ellipse">{{lang 'common.sorter.sort_by'}}</span></h4>
<a class="mobile-panel-close" href="#" data-collapsible="mobileSortBy-panel-{{type}}" data-group-collapsible="main"><svg><use xlink:href="#icon-close" aria-hidden="true"></use></svg></a>
<div class="mobileSortBy-panel-body" data-lock-body-scroll>
<ul class="navList navList--mobileSelectList">
<li class="navList-item">{{lang 'common.sorter.relevance'}}</li>
<li class="navList-item">{{lang 'common.sorter.newest'}}</li>
<li class="navList-item">{{lang 'common.sorter.price_asc'}}</li>
<li class="navList-item">{{lang 'common.sorter.price_desc'}}</li>
</ul>
</div>
</div>
SORT BY code for the mobile version. When the user is selecting an option, the code shows the "is-active" in the class, and that places a V mark next to it.
The problem is with the first option. It ignores the If statement and doesn't show the mark.
What can be done to fix it?

My Movie Review Wont Work and Tried Everything

So Every Time I type a movie in it dosent show up which it should I dont know what to Ive tried everything
// Get input element
let filterInput = document.getElementById('filterInput');
// Add event listener
filterInput.addEventListener('keyup', filterNames);
function filterNames(){
// Get value of input
let filterValue = document.getElementById('filterInput').value.toUpperCase();
// Get names ul
let ul = document.getElementById('names');
// Get lis from ul
let li = ul.querySelectorAll('li.collection-item');
// Loop through collection-item lis
for(let i = 0;i < li.length;i++){
let a = li[i].getElementsByTagName('a')[0];
// If matched
if(a.innerHTML.toUpperCase().indexOf(filterValue) > -1){
li[i].style.display = '';
} else {
li[i].style.display = 'none';
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.99.0/css/materialize.css">
<title>NinjaWolf Movie Review</title>
</head>
<body>
<div class="container">
<h1 class="center-align">
Movies Watched
</h1>
<h4 class="center-align">
*Spoiler Warning*
</h4>
<input type="text" id="filterinput" placeholder="Search Movie">
<ul id="names" class="collection with-header">
<li class="collection-header">
<h5>2019</h5>
<li class="collection-item">
ARMY OF DARKNESS
</li>
<li class="collection-item">
THE CLOVERFIELD PARADOX
</li>
<li class="collection-item">
CLOVERFIELD (2008)
</li>
<li class="collection-item">
INSIDIOUS: CHAPTER 2
</li>
<li class="collection-item">
INSIDIOUS
<li class="collection-item">
TERMINATOR: DARK FATE (2019)
</li>
<li class="collection-header">
<h5>November</h5>
</li>
<li class="collection-item">
EVIL DEAD II
</li>
<li class="collection-item">
TRANSFORMERS
</li>
<li class="collection-item">
JOKER
<li class="collection-item">
INDEPENDENCE DAY
</li>
<li class="collection-item">
MISSION: IMPOSSIBLE FALLOUT M:I-6
</li>
<li class="collection-item">
<a href="file:///D:/Website/Movie%20Review/Movies/BLACK%20MIRROR.html">BLACK MIRROR (2011 - )
</li>
<li class="collection-item">
THE LION KING(2019)
</li>
<li class="collection-item">
TERMINATOR 2: JUDGEMENT DAY
<li>
<li class="collection-item">
MISSION: IMPOSSIBLE ROUGE NATION M:I-5
</li>
<li class="collection-item">
MISSION: IMPOSSIBLE GHOST PROTOCOL M:I-4
</li>
<li class="collection-item">
DADDY'S HOME 2
</li>
<li class="collection-item">
HAPPY DEATH DAY 2 U
</li>
<li class="collection-item">
DADDY'S HOME
</li>
<li class="collection-item">
HAPPY DEATH DAY
</li>
<li class="collection-item">
THE MAZE RUNNER
</li>
<li class="collection-item">
ASSASSIN'S CREED
</li>
<li class="collection-item">
Galaxy Quest(1999)
</li>
<li class="collection-header">
<h5>October</h5>
</li>
<li class="collection-item">
Goosebumps 2(2018)
</li>
<li class="collection-item">
THE EVIL DEAD(1981)
</li>
<li class="collection-item">
EVIL DEAD(2013)</li>
<li class="collection-item">
LOVE DEATH + ROBOTS(2018)
</li>
<li class="collection-header">
<h5>September</h5>
</li>
<li class="collection-item">
MAMMA MIA
<li class="collection-header">
<h5>2018</h5>
</li>
<li class="collection-item">
ANON(2018)
</li>
</ul>
<br/>
</div>
<div class="card">
<h2>Stranger Things (Season 3)</h2>
<h4>July 17, 2019 - July 18, 2019, Stranger Things (Season 3) is about In the summer of 1985 in Hawkins, the new Starcourt Mall has become the focal point of the town, driving other stores out of business. Sheriff Jim Hopper is conflicted over Eleven and Mike's budding relationship, while Joyce considers moving out of Hawkins for better prospects, leaving the state of the children's friendships and her relationship with Hopper in the air. However, strange power fluctuations trigger Will's awareness of something otherworldly, and Eleven and Max sense something is off about the town's residents, and despite having closed the portal to the Upside Down, fears that they are all in danger from it still.</h4>
<div class="img-wrapper">
<img src="./img/ST3.png" alt="ST3">
<p>I watched Stranger Things(Season 3) on July, 17, 2019 and I loved it and Stranger Things Season 3 had an upgrade because they went into the Gorrer selection and when they cut her leg open I just couldn't watch and I know hooper is still alive and remember that scene where Steve knocks that Russian out if that was me I would have said <b>"Fuck Mother Russia"</b> and Fun Fact I always watch Stranger Things (Season 3) with my Dad and my Brother got interested in Stranger Things when Season 2 came out and my Sister said we should watch it all together but my Brother said "No Way" and watched it without us and so while we watched Stranger Things (Season 3) he was playing Apex Legends I finished it on July 18, 2019, <p>
<br> <br/>
</div>
</div>
<div class="card">
<h2>RWBY: Volume 2 (2014)</h2>
<h4>July 4, 2019, RWBY: Volume 2 is about Team RWBY begins their second semester and try to take down a crime syndicate, a task that mabye far too difficult</h4>
<img src="./img/RWBY.jpg" alt="RWBY">
<p>I watched RWBY: Volume 2 on July, 4, 2019, I loved it because it introduced alot of new characters to RWBY and a lot of backstory even though my big brother hates the animation and I love it I cant wait to watch more RWBY</p>
<br/>
</div>
<div class="card">
<h2>Spider-Man: Far from Home(2019)</h2>
<h4>June 4, 2019, Spider-Man: Far From Home is Following the events of Avengers: Endgame (2019), Spider-Man must step up to take on new threats in a world that changed forever.</h4>
<img src="Spider-Man.jpg" alt="Spider-Man: Far from Home">
<p>I watched on July 2, 2019, my Big Brother took me and my sister to Spider-Man: Far from Home as a surprise and was a great a movie and my Brother Neil thought Mysterio was great. But then the credits ruined it the whole revealing identity. what is a head-scratcher is there were only a couple of people because it was the day it comes into theaters. and in the quote of Neil "The comics after Civil War where horrible" and my Dad always told me <b>"Joshua one of these days MARVEL
will have a downfall and decrease"</b> after thinking out it I think the day has come where MARVEL has failed</p>
<br/>
</div>
<h2>RWBY: Volume 1(2013)</h2>
<h4>June 16, 2019, RWBY is about In the land of Remnant, where boys and girls train to become huntsman and huntresses, 4 color-coded Teenage girls form who Team RWBY and train to fight crime and monsters known as the Grimm, team up to fight the mysterious shadow organization in this action-packed animated series from Rooster Teeth.</h4>
<div class="image-wrapper">
<img src="RWBY.png" alt="RWBY">
</div>
<p>I watched RWBY: Volume 1 on June 14, 2019, it was an Amazing Movie or Tv Show cause I thought it was a Movie but in actuality it was a TV Show ever episode combined into a movie and I originally got into the TV Show because I would listen to the soundtrack on Pandora and then I decided that since it was on Amazon Prime I would watch it and that the category: American animated series</p>
<br/>
<div class="card">
<h2>Dragon Prince(2018)</h2>
<h4>June 10, 2019, Dragon Prince is about An extraordinary discovery inspires two human princes and an elven assassin to team up on an epic quest to bring peace to their warring lands.</h4>
<div class="image-wrapper">
<img src="http://www.nerdreport.com/wp-content/uploads/2019/02/MV5BZDkzYzZjMmItYmE1Ny00MzJkLWFkOGItOWRiNjA0M2RiOWY2XkEyXkFqcGdeQXVyMTMxODk2OTU#._V1_.jpg" alt="Dragon_Prince">
</div>
</div>
<p>I watched Dragon Prince on June 1, 2019, It was Amazing, Excellent, Stunning, Beautiful it was a TV Show. People recommended it to my sister we were laughing almost the entire time. And we were shocked to know the actor of Zuko(The Last Airbender) We loved it can't wait for the next episode</p>
<br/>
<div class="card">
<h2>Good Omens</h2>
<h4>June 2, 2019, Good Omens is a television serial based on the 1990 novel Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch by Terry Pratchett and Neil Gaiman. It's about A tale of the bungling of Armageddon features an angel, a demon, an eleven-year-old Antichrist, and a doom-saying witch.</h4>
<div class="image-wrapper">
<img src="https://i2.wp.com/www.geektown.co.uk/wp-content/uploads/2017/08/goodomens.jpg?zoom=2.625&y=850%2C370&ssl=1" alt="Good_Omens">
</div>
</div>
<p>I watched Good Omens on May 31, 2019, It's an amazing TV show we were laughing almost the whole time throughout the first Episode and the TV Show that Book is Based on is something I enjoy because they are making fun of Christianity.</p>
<br/>
<div class="card">
<h3>IT(2017)</h3>
<h5>May 3, 2019, IT retroactively as IT Chapter One)is a 2017 American supernatural horror film based on Stephen King's 1986 novel of the same name. Produced by New Line Cinema, RatPac-Dune Entertainment, KatzSmith Productions, Lin Pictures, Vertigo Entertainment, and distributed by Warner Bros. It is the second adaptation of the novel following Tommy Lee Wallace's 1990 miniseries, and a sequel is planned. The film tells the story of the summer of 1989 In the Town of Derry a group of bullied kids "The Losers Club" together to destroy a shape-shifting monster, which disguises itself as a clown and preys on the children of Derry, their small Maine town
</h5>
<div class="image-wrapper">
<img src="https://upload.wikimedia.org/wikipedia/en/5/5a/It_%282017%29_poster.jpg" alt="IT">
<p>I watched IT on May 3, 2019, an Holy Shit this scared me out of my skin and gave me chills down my spine and I was cussing almost the entire movie it scared the Living Shit out of me. I can't wait for Chapter 2 because it has James McAvoy
</div>
</div>
<div class="card">
<h3>TAG(2018)</h3>
<h5>April 29, 2019, Tag is a 2018 American comedy film directed by Jeff Tomsic(in his directorial debut)
and written by Rob McKittrick and Mark Steilen. The film is based on a true story that was published in The Wall Street Journal about a group of grown men played by Ed Helms, Jake Johnson, Hannibal Buress, Jon Hamm, Jeremy Renner, who spend one month a year playing a game of tag.
</h5>
<div class="image-wrapper">
<img src="https://image.tmdb.org/t/p/w500/eXXpuW2xaq5Aen9N5prFlARVIvr.jpg" alt="TAG" >
<p>I watched Tag on April 29, 2019, I watched Tag and OMG it was Terrific and
I imagine me all grown up and playing Tag with friends because I also love Tag.
I would give it 100% on Rotten Tomato and Me and Dad laughed almost the entire Movie</p>
</div>
</div>
<div class="card">
<h3>Avengers: Endgame(2019)</h3>
<h5>April 30, 2019, Avengers: Endgame takes place 22 or 21 days After the devastating events of Avengers: Infinity War(2018) the universe is in ruins.
With the help of remaining allies, the Avengers assemble once more to undo Thanos' actions and restore order to the universe.
It was filmed back to back with Avengers: Infinity War based on the Marvel Comics film was Directed by Anthony and Joe Russo and
Avengers: Endgame was widely anticipated, and Disney backed the film with extensive marketing campaigns. It also broke numerous box office records and has grossed over $1.4 billion worldwide,
becoming the highest-grossing film of 2019, as well as the eighth highest-grossing film of all time </h5>
<div class="image-wrapper">
<img src="https://cnet3.cbsistatic.com/img/xLgPeuq6CW9A2N2V2kKmhMT6h2o=/1092x0/2019/03/14/dd4d8d9c-5f16-4f6b-a7d8-65a00d095c2c/avengers-endgame-poster-square-crop.jpg" alt="AVENGERS_ENDGAME">
</div>
</div>
<p>I watched Avengers: Endgame on April 28, 2019, it was a masterpiece, me and my Dad, my Big Sister, my Big Brother all loved it we were laughing almost the entire Movie and 100% on Rotten Tomato.
and I loved the thought of them Time Traveling and the look on my Dads face was priceless when they time travled 2013
<br/>
</body>
</html>
let filterInput = document.getElementById('filterInput');
... selects the first element in DOM with an id value of filterInput. Unfortunately, you have 0 elements in your markup with that id value. You probably want to use
let filterInput = document.getElementById('filterinput');
^
In the future, whenever you're getting unexpected results, use a console.log() (or a breakpoint) to look at what's inside your variables. In your case,
let filterInput = document.getElementById('filterInput');
console.log(filterInput);
... would have immediately revealed the problem.
Welcome to StackOverflow!
See it working:
let filterInput = document.getElementById('filterinput');
filterInput.addEventListener('keyup', filterNames);
function filterNames() {
const filterValue = filterInput.value.toUpperCase();
const ul = document.getElementById('names');
const li = ul.querySelectorAll('li.collection-item');
for (let i = 0; i < li.length; i++) {
const a = li[i].getElementsByTagName('a')[0];
if (a.innerHTML.toUpperCase().indexOf(filterValue) > -1) {
li[i].style.display = '';
} else {
li[i].style.display = 'none';
}
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.99.0/css/materialize.css" rel="stylesheet"/>
<div class="container">
<h1 class="center-align">
Movies Watched
</h1>
<h4 class="center-align">
*Spoiler Warning*
</h4>
<input type="text" id="filterinput" placeholder="Search Movie">
<ul id="names" class="collection with-header">
<li class="collection-header">
<h5>2019</h5>
</li>
<li class="collection-item">
<a href='#'>ARMY OF DARKNESS</a>
</li>
<li class="collection-item">
<a href='#'>THE CLOVERFIELD PARADOX</a>
</li>
<li class="collection-item">
<a href='#'>CLOVERFIELD (2008)</a>
</li>
<li class="collection-item">
<a href='#'>INSIDIOUS: CHAPTER 2</a>
</li>
<li class="collection-item">
<a href='#'>INSIDIOUS</a>
</li>
<li class="collection-item">
<a href='#'>TERMINATOR: DARK FATE (2019)</a>
</li>
<li class="collection-header">
<h5>November</h5>
</li>
<li class="collection-item">
<a href='#'>EVIL DEAD II</a>
</li>
<li class="collection-item">
<a href='#'>TRANSFORMERS</a>
</li>
<li class="collection-item">
<a href='#'>JOKER</a>
</li>
<li class="collection-item">
<a href='#'>INDEPENDENCE DAY</a>
</li>
<li class="collection-item">
<a href='#'>MISSION: IMPOSSIBLE FALLOUT M:I-6</a>
</li>
<li class="collection-item">
<a href='#'>BLACK MIRROR (2011 - )</a>
</li>
<li class="collection-item">
<a href='#'>THE LION KING(2019)</a>
</li>
<li class="collection-item">
<a href='#'>TERMINATOR 2: JUDGEMENT DAY</a>
</li>
<li class="collection-item">
<a href='#'>MISSION: IMPOSSIBLE ROUGE NATION M:I-5</a>
</li>
<li class="collection-item">
<a href='#'>MISSION: IMPOSSIBLE GHOST PROTOCOL M:I-4</a>
</li>
<li class="collection-item">
<a href='#'>DADDY'S HOME 2</a>
</li>
<li class="collection-item">
<a href='#'>HAPPY DEATH DAY 2 U</a>
</li>
<li class="collection-item">
<a href='#'>DADDY'S HOME</a>
</li>
<li class="collection-item">
<a href='#'>HAPPY DEATH DAY</a>
</li>
<li class="collection-item">
<a href='#'>THE MAZE RUNNER</a>
</li>
<li class="collection-item">
<a href='#'>ASSASSIN'S CREED</a>
</li>
<li class="collection-item">
<a href='#'>Galaxy Quest(1999)</a>
</li>
<li class="collection-header">
<h5>October</h5>
</li>
<li class="collection-item">
<a href='#'>Goosebumps 2(2018)</a>
</li>
<li class="collection-item">
<a href='#'>THE EVIL DEAD(1981)</a>
</li>
<li class="collection-item">
<a href='#'>EVIL DEAD(2013)</a></li>
<li class="collection-item">
<a href='#'>LOVE DEATH + ROBOTS(2018)</a>
</li>
<li class="collection-header">
<h5>September</h5>
</li>
<li class="collection-item">
<a href='#'>MAMMA MIA</a>
</li>
<li class="collection-header">
<h5>2018</h5>
</li>
<li class="collection-item">
<a href='#'>ANON(2018)</a>
</li>
</ul>
</div>

How to find Xpath for read the list of elements use list<Webelement>

webdriver finding xpath its too dificult for me. i used fire path most of fire path given xpath not working and its too lengthy. some one give me idea about xpath will work all conditions and i know relative xpath
some times this posibilities also not working like {//ul[#class='review-nav']}. some one help me for find xpath that xpath will work all conditions
<ul class="review-nav">
<li id="pend" class="pend tabclass">
<a onclick="OnTabSelect(1,'pend',0)" href="#">Pending (197)</a>
<span class="glyphicon glyphicon-filter filterclass" style="color:#185daa;top:4px;display:none"/>
</li>
<li id="flag" class="flag tabclass active">
<a onclick="OnTabSelect(4,'flag',1)" href="#">Flagged (96)</a>
<span class="glyphicon glyphicon-filter filterclass" style="color:#185daa;top:4px;display:none"/>
</li>
<li id="esca" class="esca tabclass">
<a onclick="OnTabSelect(5,'esca',2)" href="#">Escalated (88)</a>
<span class="glyphicon glyphicon-filter filterclass" style="color:#185daa;top:4px;display:none"/>
</li>
<li id="closed" class="closed tabclass">
<a onclick="OnTabSelect(3,'closed',3)" href="#">Closed (99)</a>
<span class="glyphicon glyphicon-filter filterclass" style="color:#185daa;top:4px;display:none"/>
</li>
<li id="all" class="all tabclass">
<a onclick="OnTabSelect(0,'all',3)" href="#">All (1,355)</a>
<span class="glyphicon glyphicon-filter filterclass" style="color:#185daa;top:4px;display:none"/>
</li>
</ul>
I try this Xpath to read above list its not working
xpath = //ul[#class='review-nav']
Sorry for that, I am little bit not clear for what you need xpath..
If you are trying to get all link ('a') to collect into List
//ul[#class='review-nav']/li/a
If you are trying to get all 'span' element to collect into List
//ul[#class='review-nav']/li/span
If you want to get specific element in specific li, you can try with id of 'li', for example if you like to find xpath of 'a' in first li
//li[#id='pend']/a
Thank You
Try with CSS:
.tabclass
You should get the 'li' elements with this.

How to get span class text using jsoup

I am using jsoup HTML parser and trying to travel into span class and get the text from it but Its returning nothing and its size always zero. I have pasted small part of HTML source . pls help me to extract the text.
<div class="list_carousel">
<div class="rightfloat arrow-position">
<a class="prev disabled" id="ucHome_prev" href="#"><span>prev</span></a>
<a class="next" id="ucHome_next" href="#"><span>next</span></a>
</div>
<div id="uc-container" class="carousel_wrapper">
<ul id="ucHome">
<li modelID="587">
<h3 class="margin-bottom10"> Ford Figo Aspire</h3>
<div class="border-dotted margin-bottom10"></div>
<div>Estimated Price: <span class="cw-sprite rupee-medium"></span> 5.50 - 7.50 lakhs</div>
<div class="border-dotted margin-top10"></div>
</li>
<li modelID="899">
<h3 class="margin-bottom10"> Chevrolet Trailblazer</h3>
<div class="border-dotted margin-bottom10"></div>
<div>Estimated Price: <span class="cw-sprite rupee-medium"></span> 32 - 40 lakhs</div>
<div class="border-dotted margin-top10"></div>
</li>
I have tried below code:
Elements var_1=doc.getElementsByClass("list_carousel");//four classes with name of list_carousel
Elements var_2=var_1.eq(1);//selecting first div class
Elements var_3 = var_2.select("> div > span[class=cw-sprite rupee-medium]");
System.out.println(var_3 .eq(0).text());//printing first result of span text
please ask me , if my content was not very clear to you. thanks in advance.
There are several things to note about your code:
A) you can't get the text of the span, since it has no text in the first place:
<div>Estimated Price:
<span class="cw-sprite rupee-medium"></span>
5.50 - 7.50 lakhs
</div>
See? The text is in the div, not the span!
B) Your selector "> div > span[class=cw-sprite rupee-medium]" is not really robust. Classes in HTML can occur in any order, so both
<span class="cw-sprite rupee-medium"></span>
<span class="rupee-medium cw-sprite"></span>
are the same. Your selector only picks up the first. This is why there is a class syntax in css, which you should use instead:
"> div > span.cw-sprite.rupee-medium"
Further you can leave out he first > if you like.
Proposed solution
Elements lcEl = doc.getElementsByClass("list_carousel").first();
Elements spans = lcEl.select("span.cw-sprite.rupee-medium");
for (Element span:spans){
Element priceDiv = span.parent();
System.out.println(priceDiv.getText());
}
Try
System.out.println(doc.select("#ucHome div:nth-child(3)").text());

Click a link in IE through VBA

I am trying to click a link but it is different from others links I have made it. I don't have a field called "id" or something.
Here is the HTML. I need it to click "pibmunic super" button/link. The FIREPATH XPath shows .//*[#id='informacoes_estatisticas']/ul/li[20]/span
<div id="informacoes_estatisticas">
<h3 class="titulo">Informações Estatísticas</h3>
<ul class="links">
<li class="item Censo Agropecuário_2006">
<li class="censo2010 super">
<li class="educa super">
<li class="empresas super">
<li class="vida super">
<li class="item Estimativa da População 2014_">
<li class="prodext2013 super">
<li class="financas super">
<li class="frota super">
<li class="item Fundações Privadas e Associações sem Fins Lucrativos no Brasil 2010_">
<li class="item Índice de Desenvolvimento Humano Municipal - IDHM_">
<li class="instfin super">
<li class="item Mapa de Pobreza e Desigualdade - Municípios Brasileiros_2003">
<li class="morbid super">
<li class="prodpec2013 super">
<li class="item Pesquisa Nacional de Saneamento Básico_2008">
<li class="item Produção Agrícola Municipal - Cereais, Leguminosas e Oleaginosas_2007">
<li class="lavperm2013 super">
<li class="lavtemp2013 super">
<li class="pibmunic super">
<span class="super">Produto Interno Bruto dos Municípios</span>
<ul class="pibmunic sub">
</li>
<li class="partpol super">
<li class="assismed super">
<li class="snig_censo2010 super">
</ul>
</div>
I am trying to write my code as something like this
Set m = html.getElementById("something")
Set a = m.getElementsByTagName("something")(something)
a.Click
I am not sure this is right, I have tried lots of combinations and it does not work. I don't know exactly which "getelementsby" I should use or what to give the command inside ().
Hope you can help me !! thanks
All of your classes seem to be unique. If that's the case you should change all the class attributes to id attributes ex:
class="something"
to
id="something"
Once you do that getElementById("something") will work. getElementsByTagName() returns an array of elements with a specific tag. ex:
getElementsByTagName("li")
retrieves all the li elements under a node.
If the newest VBA supports querySelectorAll() that will allow you to use CSS selectors to find elements. ex:
querySelectorAll(".something")
This will find all elements with the class something. However, since there can be multiple elements with the same class, you will get an array as a result. You can either loop over these elements to process them, narrow your selector, or get the first index of the returned array.
If VBA still does not support querySeletorAll() and you will need to combine getElementsByTagName() with a loop over the matching tags to find elements with the something class. ex:
For Each el in getElementById("container").getElementsByTagName("li")
For Each cl in el.className.Split(' ')
If cl = "something" Then
el.onclick()
End If
Next
Next
I would recommend assigning Id's or if at all possible use JavaScript or jQuery. They are more specialized at handling at these tasks (more abstraction). jQuery would be as simple as:
$(".something").trigger("click");