I am trying to read an html page in my java code using Jsoup library. This is the link to the page: http://www.alkhaleej.ae/
The part in the page that I am interested in is the horizontal menu bar at the top of the page (which has the news categories). When I right click on that menu bar and choose inspect element, the html elements of interest are visible to me under the tag <div id="MainMenuCenter">. However, when I run my code, it turns out this tag is actually empty, and all the children of this tag get invisible. I also tried to view the complete document using "view page source" on the webpage. I surprisingly found this element empty (no children) as below.
<div id="MainMenuCenter">
</div>
Therefore, I am not able to access the information I need in my code. What is really going on? Did the developers hide the children of this element on purpose? Can you suggest a way to make the children visible to my code? Thank you.
You can retrieve the data by looking at the network traffic on
Inspect element -> Network
Check the traffic one by one or use the find tools.
If you find the match data, you can re-obtain it by visiting the url who serve the data..
Maybe like: http://example.com/serve.php?category=car&page=1
Related
I have a few nav bar items that I am trying to find with driver.findElement(by.id("menu-news-menu-item")) and driver.findElements(by.id("menu-news-menu-item")). It can't find them for some reason. I have verified that the id is correct on the site but it still can't be found. I know there are other ways to get to the info, but it is my understanding that using the id is the best way to go about finding elements. Below I have included an HTML snippet of what I am trying to search for. If I need to provide any more information please let me know.
<div class="navbar-collapse collapse">
<li>
<a id="menu-news-menu-item" href="/novus/news">News</a>
</li>
</div>
From looking at your HTML I see one potential problem. There may be more.
The top level DIV you posted has a class navbar-collapse collapse. That indicates to me that that DIV is collapsible and is currently collapsed which means that any of its children will be hidden. Selenium was designed to allow the user to only interact with visible elements. This means that if you search for your A tag by ID and it's a child of the DIV that is currently collapsed, Selenium won't find it. What you need to do before you search for the A tag is to unhide it. I don't know for sure how to do this but it probably involves clicking the collapsible DIV.
With this info, try to figure the rest out on your own. You should be able to investigate the page HTML, try some code, and see what happens. If it doesn't work and you get stuck. Come back and post some more of the surrounding HTML, the code you tried, and the result (error messages, etc.) and we'll try to help you more.
For example, go to Yahoo, and try to right click -> inspect element on the arrow button eluded to in the picture below.
Nothing will popup so I'm unable to inspect element, and when inspecting the DOM I cannot seem to locate this element their either.
Any guidance one how to add this functionality back in would be greatly appreciated!
Update: Here is a screenshot of what the DOM looks like when I try to select the element.
The div below the one I have highlighted only selects the pictures and captions between the arrow buttons.
I did got to Yahoo.com, and tried inspecting the element that you have shown. I was able to inspect it normally. [ Im using Chrome, on Mac - Yosemite ].
Here is the code that I found. May be you can use that.
<button type="button" class="FilmstripBtn NextBtn ButtonNaked Wpx-20 Pos-a End-0 T-0 B-0 Fz-30 Z-1 " data-jump-to="next" title="Next" data-action-outcome="pgnt" data-ylk="t1:a3;t2:td;t3:nav;sec:td-fea;elm:btn;elmt:ne;itc:1;" data-rapid_p="6" id="yui_3_12_0_1_1431061078340_1326"><i class="Icon W-a" id="yui_3_12_0_1_1431061078340_1329"></i></button>
Made a little progress. For some reason Chrome still won't let me right click inspect element (maybe a bug), but I was able to find the buttons in the elements tab. They are actually "a" tags and not buttons on my end.
I had difficulty before because they are labeled differently for me than what is shown from the other response to this question, and the "a" tags won't become highlighted unless I expand the divs and select the actual "a" tag (possibly another chrome bug?).
I'm trying to click on a particular link in a webpage. Basically this is a Home button. So whereever I browse, I always find this button is same position.
As of now I use driver.findElement(By.xpath("//span/ul/li/a")).click(); command to click on this, but this is not working in all the webpages even though the xpath don't change. here is the firebug view of the link.
the id is not static, it keeps on changing. So what are the other ways I can detect this link ?
You can use By.linktext()
driver.findElement(By.linkText("Home")).click();
As dirkk said, you can always locate an element through a By.linkText() selector, although this could be a fickle solution: the "home" link text could eventually change (in which case your selector won't work anymore), there could be other "home" links on the page (in which case you wouldn't necessarily obtain the element you want) or the "home" link text might be different in a different language (in which case your selector will only work when testing the English site).
If you have control over the generated HTML code, you should try adding a static ID or even a class to this link and look it up through a By.id() or By.cssSelector() selector.
If you don't, try using a selector that relies more on semantics (IDs and classes) than structure (tag hierarchies). That way your selector will be more stable and easier to understand as well. But in the end, that's not always possible if you test an untestable external website.
Hi firstly i want to mention that i am aware of ajax based application and reuse of same page.
The requirement here is that, i want to have two separate pages one for login and other for the main application. Now, this is not because i just want it, but because i have very different layouts in the two pages which i am comfortable to put together with html elements and css directly in the page and then putting divs to contain dynamic html for gwt to populate.
Even in case of myfaces i have not seen application with same page for login and the main app page.
Anyways, the problem i am facing is, lets say i have two pages
Login.html with a div : div id="login"
Main.html with a div: div id="main"
i have declared both of them in my welcome file list in web.xml
Now i start with Login page fill the "login" div with gwt widgets and on click of a button
i am using following jsni code to redirect to "/Main.html?gwt.codesvr=127.0.0.1:9997"
private native void gotoURL(String url) /-{
$wnd.location.href=url;
}-/;
and then trying to populate the "main" div. But the behaviour as i noticed is that the application call the entry point again and it doesnt find any element as "login" and gives NPE.
Is there a way to do this? also to get rid of the "?gwt.codesvr=127.0.0.1:9997"?
Thanks
First, you don't want to add the ?gwt.codesvr=... stuff - it's related only to hosted (debugging of gwt) mode. You could use a relative url (for example simply "Main.html"). But since you can only have a single entry point, you need to either split the app into two client modules (two separate apps actually) or dispatch in your entry point according to the url (whether you've landed on Login.html or Main.html)
Second, what I would do in this scenario is have an empty html with no layout except a single div for the dynamic content as the only html page of the app. Then I would use 2 UiBinders - one for the main page, and one for login, and use a hash suffix in the url (using GWT's history event and management, and hyperlink widgets) to know where I am. Maybe you should read more in GWT's documentation on history and stateful apps. Try http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsHistory.html#stateful
I'm looking to create a horizontal menu in a jsp page - the menu items vary by user but stay consistent over every page in the site for that user apart from the appearance of the active tab. Seems a simple enough problem at first (the appearance is modified using css) but I can't decide where to construct the menu.
Menu code:
<ul>
<li>item1</li>
<li id="active">item2</li>
</ul>`
As I see it there are 3 choices of when to retrieve menu items:
Upon receipt of HTTP Request to any controller for the first time store two arrays in the session - [url1, url2] and [item1, item2]. Then make the all the jsp pages form this into the above code. The jsp would have to know it's url to make against the [url1, url2] array in order to insert the active id.
Create the above html separately in each controller. Since a controller knows it's own url, it's simple to add the active id.
Create above html without any active id, store the html in the session and make either the jsp pages/controllers modify the html string.
None of these seem particularly appetising.
Does anyone have any advice on this?
Since a JSP is where all the HTML belongs, I'd go for option 1, but then with a List<MenuItem> instead of two loose arrays. You can find JSP's own URL by ${pageContext.request.requestURI}. The JSTL functions library should be helpful in determining whether the URL matches.