ChromeDriver -Element ID or Xpath changes - java

I have a quick question , I created some test cases using chrome driver on a Friday , today I returned and all test cases have failed ,when I checked I see that all the elements ID's or xpaths have changed , My question is why did this happen? I also need to know does this happen often?
Thank you

Please Check your web pages which are used for testing,
Element ID or Xpath changes mainly due to the frameworks which is used for the web page development. (i.e) like ExtJS based applications will basically generate dynamic ids. So if any components/elements are added to the web pages, it will automatically re-generate their ids.
Please refer to this SO post.

My question is why did this happen? -- Possibly reason in this scenarios could be :
UI of Web Page has changed, so that your XPATHs are failing.
Your XPATH may contains alphanumeric characters(or may be too long absolute path), which is not a good web locating strategy. You may want to switch to different locators for stability.
I also need to know does this happen often? -- It can happen at any point of time. (Lots of Web applications are changing their user Interface to give good user experience)

The Application you are working is dynamic. everytime you refresh a page or sends some data to server, the dynamic element changes it attribute values. I recommend you go with dynamic xpaths. you will find many learning sites to break the ice!!
Hope this helps!!

Related

Unable to access certain URLs with Selenium Java

I am in the process of writing a program whose purpose is centered around generating custom URLs for intelius.com and then extracting data from them with selenium. I have observed interesting behavior that I am unsure how to address.
My program creates URLs after the following pattern: https://intelius.com/people-search/LASTNAME/CITY-STATE, but I have found that attempting to access these constructed links consistently leads to a timeout error.
For example, http://intelius.com/people-search/Williams/Brooklyn-NY does not load the expected results page
Digging around in the website's source, I have found what appears to be a link validator script — what exactly that means, I do not know — and am unsure how to proceed.
How exactly would I go about authenticating my queries, without programming selenium to manually input the data into the search textbox and to press the submit button? Is my link-construction approach flawed in some blatantly obvious manner? I am a bit lost and would appreciate some direction. Thanks!
I think your problem is using http instead of https, and omitting www from URL. So this works:
https://www.intelius.com/people-search/Williams/Brooklyn-NY
The problem lies in the way the URL being formed. You need to construct and pass the arguments the way the web application understands it. The following works -
https://www.intelius.com/people-search/William-Brooklyn/NY

JSP/Tomcat: Navigation system with sub-folders but one page

My JSP project is the back-end of a fairly simple site with the purpose to show many submissions which I want to present on the website. They are organized in categories, basically similar to a typical forum.
The content is loaded entirely from a database since making separate files for everything would be extremely redundant.
However, I want to give the users the possibility to navigate properly on my site and also give unique links to each submission.
So for example a link can be: site.com/category1/subcategory2/submission3.jsp
I know how to generate those links, but is there a way to automatically redirect all the theoretically possible links to the main site.com/index.jsp ?
The Java code of the JSP needs access to the original link of course.
Hope someone has an idea..
Big thanks in advance! :)
Alright, in case someone stumbles across this one day...
The way I've been able to solve this was by using a Servlet. Eclipse allows their creation directly in the project and the wizard even allows you to set the url-mapping, for example /main/* so you don't have to mess with the web.xml yourself.
The doGet function simply contains the redirection as follows:
request.getRequestDispatcher("/index.jsp").forward(request,response);
This kind of redirection unfortunately causes all relative links in the webpage to fail. This can be solved by hardlinking to the root directory for example though. See the neat responses here for alternatives: Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP

Wicket appending weird number

I've figured a weird issue with Wicket 1.5.x. All of the sudden, wicket started to append a number that increases to every url which looks like mydomain.com/home?1. For every Bookmarkable link I click, wicket sends a redirect to the browser increasing that number. Same happens for when trying to clean the url and calling mydomain.com/home I end up with another redirect and an increased number.
What's even worse is that on Google App Engine the version number when clicking a link increase by the factor of two which also seems to cause issues with submitting forms which simply do.. well.. nothing!?
I've tried to play around with setVersioned(false)/true and setStatelessHint(false)/true without any result. What could that be, how to get rid of it and how can it influence my app not working on GAE?
thanks a bunch
Alex
EDIT:
It looks like wicket is always incrementing the version for my page as my base page is stateful (shows user's name if any in a model). But nothing changes on the site yet clicking i.e. my Bookmarkable Link to my home site increases it's page id with every click so if the user clicks 10x times on the home link his history is polluted with 10 entries of the exactly same page as nothing has changed.. this doesn't make any sense at all so I am curious how to fix that without loosing being stateful!?
The number represents the version of the page. It appears when the page is stateful (thus the server must track its state).
It takes a little more than set the stateless hint to make a page stateless. You must avoid any component that holds state on the server side, and use stateless alternatives (StatelessForm instead of Form, StatelessLink instead of Link).
I answered this question with an example of a stateless page: Is it difficult to make a mainly stateless web application with Wicket?
There is a Jira ticket: setVersioned(false) should force single Page Version about this issue. The question has also been discussed in the mailing list. Expected complications: Page Reload on Submit of non-versioned Page

how to extract HTML data from a webpage which scrolls down for a fixed number of times?

I want to extract HTML data from a website using JAVA. The problem is the webpage keeps scrolling down once the user reaches the bottom of the page. Number of times it scrolls down is fixed. My JAVA code can extract only for the 1st part. How do I extract for the remaining scrolls? Is there a way to load the whole page at once with JAVA? ANy help would be appreciated :)
This might be the type of thing that PhantomJS (http://phantomjs.org/) was designed for. It will crawl entire web pages and even execute JavaScript, using a "real" browser in headless mode. I suggest stopping what you're doing with Java and take a look at PhantomJS instead. It could save you a LOT of time. :)
This type of behavior is implemented in the browser, interpreting the user's scrolling actions to load more content via AJAX and dynamically modifying the in-memory DOM in the browser. Consider that your Java runs in a web container on the server, and that web container (i.e. Tomcat, JBoss, etc) provides a huge amount of underlying code so your app doesn't have to worry about the plumbing.
Conceptually, a similar thing occurs at the client, with the DHTML web page running in its own "container" (the browser), which provides a wealth of functionality, from UI to networking, to DOM, etc. If you remove the browser from the equation and replace it with a Java program, you will need to provide the equivalent of the browser in which the DHTML/Javascript can execute.
I believe that HTMLUnit may fill the bill, but have not worked with it personally.

Launching a website from within a program, and inputting data to specific fields

Although I've been programming for a few years I've only really dabbled in the web side of things, it's been more application based for computers up until now. I was wondering, in java for example, what library defined function or self defined function I would use to have a program launch a web browser to a certain site? Also as an extension to this how could I have it find a certain field in the website like a search box for instance (if it wasnt the current target of the cursor) and then populate it with a string and submit it to the server? (maybe this is a kind of find by ID scenario?!)
Also, is there a way to control whethere this is visible or not to the user. What I mean is, if I want to do something as a background task whilst the user carries on using the program, I will want the program to be submitting data to a webpage without the whole visual side of things that would interrupt the user?
This may be basic but like I say, I've never tried my hand at it so perhaps if someone could just provide some rough code outlines I'd really appreciate it.
Many thanks
I think Selenium might be what you are looking for.
Selenium allows you to start a Web browser, launch it to a certain website and interact with it. Also, there is a Java API (and a lot of other languages, by the way) allowing you to control the launched browser from a Java application.
There are some tweaking to do, but you can also launch Selenium in background, using a headless Web browser.
as i understand it you want to submit data to a server via the excisting webinterface?
in that case you need to find out how the URL for the request is build and then make a http-call using the corresponding URL
i advice reading this if it involves a POST submit

Categories