I am currently working on creating functional tests using htmlunit.
On the webpage I am testing, there is an anchor which opens a page in a new tab when clicked. This anchor needs to be clicked to reveal additional check boxes and buttons.
If I wanted to save the page after clicking the anchor it would look something like this:
HtmlAnchor terms = tb.getFirstByXPath("//*[#id=\"terms_link\"]");
tb = terms.click();
However, the above code saves the webpage which is opened in the new tab as opposed to the web page in which the anchor was clicked.
Is there any way for me to save the page in which the anchor was clicked, or possibly save both html pages?
So after a bit of messing around I discovered that any actions which change the page are registered in the browser window regardless of whether or not you save them after an action.
In order to save the popup which occurs after clicking the an action just assign the resulting page to an HtmlPage object.
HtmlPage page = button.click
You can fetch the previous window and save it's modified contents with the following code. If you want to save the popup and the original page just save them to different object names.
page2 =(HtmlPage)(webClient.getWebWindows().get(0).getEnclosedPage());
Related
I have a JSF form of view *.jspx page. The form has around 20 fields. I have a print preview button, that would open a new browser window and show print preview of this form, making all the form content as read only.
I have done a bit of workaround like setting a boolean flag in Managed bean as showprintPreview. This approach has almost done the job by showing all the fields in readonly and buttons as disabled mode.
But, I don't want to change the backing bean object.
I'd like to show the print preview with css or javascript for a jsf form.
UPDATE:
I have tried another way by using onclick on print preview button that would call predefined, window.print() js function. But its displaying all the buttons as well. I would like to hide buttons like submit, back etc in print preview and show all the input fields like text, textarea etc.
I would reuse part of page wich you want to print. Create new page only with this reusable part. then on button action open this new page in new window (target="_blank") in print preview you mentioned.
I am writing a program in Htmunit where I need to fill in two fields with text, but to get to these fields I need to click on a button to allow for the fields to appear on the screen. I cannot create a new button and click it because that will return a new "page" which I do not want. What other way is there to click on a button without creating a new page, but rather stay on the same page. For reference, I am using this website. The page I need to do this on is the page after the terms acceptance page. I need to click on "foreclosure search", then enter information to the fields.
I have an application which I am trying to test with WebDriver. On one page, the user selects a data source and some other options and then clicks next. When the user clicks next, they are presented with a page which has a list of documents that they must upload prior to submitting a request.
On the page with the documents that they must upload I am attempting to get the names of the documents and then compare them with a spreadsheet which has the list of required documents based on the data source the user chooses.
Here is my problem, I am trying to get the document names off the website. I first tried it with
String docOne = driver.findElement(By.xpath(/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div/div/h5)).getAttribute("textContent").toString();
System.out.println(docOne);
When I run this, it cannot find the element.
I then tried the following:
String docOne = driver.findElement(By.xpath("id('41027')/div[1]/h5")).getAttribute("textContent").toString();
System.out.println(docOne);
When I ran this, it could not find the element, I then manually tested this and found that every new request has a new ID, even though the first xpath I tested does not change.
My question then is, how do I get this to work? Since the element changes everytime I run the test?
I apparently had some brain flatulence this morning.
When automation clicks next to get to the documents page the page is scrolled all the way to the bottom and the top elements apparently cannot be found. I put a long delay 30 seconds and scrolled to the top of the page manually and the test passed with the first xpath I mentioned.
So I selected a web element which is always visible and told it to do a send keys with a page Up command, and it worked swimmingly.
This was something which was cracking my head for sometime.
I have a Web Page written in ExtJS+Java EE (Page A). I want to create a
new browser tab on Button click and show page B.
B does some operation and does a complete form submit.
The result of this form submit has to be displayed in A (Which is open all the while).
For Example:
In Page A, I search for the tests available in the my learning management system and display it in a grid.
When the user clicks on a test, a new window opens with the test's url (Page B).
Once the user completes the test he clicks the submit in B.
The results of the test is shown on the grid in Page A.
The big problem is that I done have much control over the Page B or its source.
Any suggestions much appreciated.
It sounds like you would need to do a window.open('Whatever Page B's url is'); when you click on the correct link per row in the grid.
From Page B, you could use window.opener to reference Page A. So you can either refresh Page A by doing something like:
window.opener.location.reload();
or you could call whatever refresh type method that you define in Page A from Page B eg. window.opener.customMethod()
I have a form where user can select an image out of list of images.
I would like to have a button "Select image".
When button is pressed there should be pop-up or overlay with the list of available images.
When user selects an image, the id of image should be returned to the original form.
I totally have no clue how to do this.
Any help would be appreciated.
This should be pretty simple:
On click of "Select", show a div (mark it with high zindex to have popup behaviour or use jQuery dialog)
On this popup add all your images (whether you would like to add the images in html table or use div is upto you)
Add listener to your images (if all your images have a single class then somehting like :
jQuery('.imgclass').click)
When user close this div, use the id which you will capture in step 3.