Elements divs = doc.select("#mp-itn b a");
In this the mp-itn is the id of a div tag. What is this b and a?
what does it signify?
I am not able understand this. Please let me know some good tutorials on jsoup.
They refer to link tag <a ...></a> and bold tag <b></b>. So in that example it selects the a tags within bold tags within the tag that has an id of mp-itn.
I suggest you read the documentation before you do anything else. It explained this in the selector-syntax page.
Related
I want to send a text to a div element in web.whatsapp. I tried several ways ie using XPath, cssSelector, class name etc. but none is working for me.
This textbox comes when we attach an image in web.whatsapp.
Please step into the div and use the div with the class "selectable-text". As this is a contenteditable div you should be able to click into it and call then sendKeys() onto the element.
if this does not help please let me know then I will look in our code how we are filling such divs exactly.
You need to drill down further until you get to a web element that takes an input.
Is it possible to click an element through selenium by a partial value of an onclick element? I had try using xpath but it seems not working even on partial value.
There are multiple input items on a page, and I only need to onclick on specific string = 锁定. Kindly advise , Thanks you
HTML:
<button class="button_d" onclick="lock('/deposit/ajaxLock.html?oid=12016062862662862','锁定')">锁定</button>
<button style="display:" class="button_d" onclick="depositOk(this , '12016062862662862',53309)">确定</button>
MY CODE :
driver.findElement(By.xpath(".//input[contains(#onclick, '锁定')]")).click();
I'm not an XPath expert but this CSS selector should do what you ask. It's looking for a BUTTON that has an onclick attribute that contains the string, 锁定.
driver.findElement(By.cssSelector("button[onclick*='锁定']")).click();
You could also just look for a BUTTON that contains the desired string. The onclick string and button text seem to be the same, at least in the example HTML you provided.
Some CSS selector references if you want to learn more...
CSS Selector reference
CSS Selector Tips
how to get the text "xxxx" and it's url using JSOUP.
<div style="width:45%;float:left;border: dashed 1px #966;margin:0 10px;padding:10px;height:400px;">
<ul>
<li>xxxx</li>
<li><b>years:</b>2015</li>
<li><b>language:</b>non </li>
<li><b>color:</b>color</li>
</ul>
</div>
This is my current approach but I receive nothing:
Elements mvYearElement = doc.select("div[style*=width:45%;float:left;border: dashed.1px #966;margin:0 10px;padding:10px;height:400px;]");
The problem is probably that styles do not need to appear in an particular order. Your selector however fixates the order and lists a lot of styles. I would try to identify the part of the style the really is discriminating the link and only use this part. Since I don't know the rest of the HTML i only could guess what is that discriminating part. This maybe?
Elements els = doc.select(div[style*=dashed]);
That is only a wild guess however. But maybe it is also the contents of the div that are discriminating it from the others? In that case you could do something like this:
Elements els = doc.select(div[style]:has(ul));
Or something else. If you would share more of the HTML I could be more specific.
I want to get a list of values from an HTML document. I am using HTMLUnit.
There are many span elements with the class topic. I want to extract the content within the span tags:
<span class="topic">
Lean Startup
</span>
My code looks like this:
List<?> topics = (List)page.getByXPath("//span[#class='topic']/text()");
However whenever I try to iterate over the list I get a NoSuchElementException. Can anyone see an obvious mistake? Also links to good tutorials would be appreciated.
If you know you'll always have an <a> then just add it to the XPath and then get the text() from the a.
If you don't really know if you always will have an a in there then I'd recommend to use the .asText() method that all HtmlElement and their descendants have.
So first get each of the spans:
List<?> topics = (List)page.getByXPath("//span[#class='topic']");
And then, in the loop, get the text inside each of the spans:
topic.asText();
text() will only extract the text from that element, and that example you've given has no text component, only a child element.
Try this instead:
List<?> topics = (List)page.getByXPath("//span[#class='topic']");
I have a HTML code where i have the div with same id can we extract the second one.
HTML code
<div id="test>example </div>
<div id ="test">example11</div>
I need to extract the example11
This works (?s)<div id="test>.*<div id ="test">(.*?)</div> but i have a lot of div with same ID so this wont be good so can any one tell me do we have any other way to extract the content.
I know REGEX is not good for HTML paring and i have no choice.
try this !
<div.*>.*</div><div.*>(.*)</div>
now you can select the first group. and its done ;)
a dirty solution would be
<div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>.*</div><div.*>(.*)</div>
hehe but aint so proud about this one ofc....uhm...will think about it..