I wanted to run a selenium test that checks whether it navigates to a new page when the button in the old page is clicked. Then I wanted to test whether it navigates back to the old page when the button in the new page is clicked.
The test works correctly when i click on the button on the first page and check whether the button element on the new page appears. But when i use selenium to click on the button element on the second page and check if the button element on the first page has appeared, it fails to find the button element on the first page, although i used the same button element to go the second page the first time and i can see that the first page is loaded. i tried usign the following wait statements:
waitForPageToLoad()
waitForTextPresent("", "text on first page")
waitForElementPresent("" , //path to first button element)
WebElement element = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(By.xpath("path to first button elment")));
None of the above wait statements work although the same element was found when the page was first initialized.
Realized that the second time the first page is refreshed i had to first do driver.switchTo().frame(driver.findElement(By.xpath("path to iframe")) as the application was inside an iframe. So it could not find the elements the second time, unless i first switch to the iframe inside.
Related
This is more of an architectural question, so in a webpage I have a edit button when allows me to edit a record. As soon as I press the edit button a modal opens up I change some of the records info and I hit save.
The focus returns to the (X) close button of the toast(save confirmation) for a second and even before the toast disappears focus returns to the browser since the save refreshes the page and the dom is destroyed and created again.
What we expect to do is once we hit the save button in the modal, focus should go to the toast (x) close button and wait till the confirmation dialog(toast) disappears and then return to the edit button again.
So there is 2 problems to be solved
How to set focus on the edit button(trigger) when the dom is destroyed and created again once we hit save button in the modal, coz there are a few buttons before that like new, view and then edit. how to specifically set focus on the trigger element?
How to create focus stack where we can specify that the focus should go to toast first and the n to the trigger even if the dom is destroyed and created again (is that possible)?
When I say "the dom is destroyed and created again" is it about replacing DOM content partially? Or the whole page is reloaded?
Just the header panel in which these trigger buttons (New, Edit, View) are destroyed and created again. So only partially the dom is destroyed and created again
A toast message is typically temporary and goes away on its own. It should be unobtrusive so that it can be easily ignored. If you have an X close button and you want to user to click on it (or hit ESC) to dismiss the toast message, then you really have a modal dialog instead of a toast message.
On sites that I've used that allow editing and saving, I've found that just a simple save message right on the page is sufficient. The save message can be an aria-live region so that the message is read for screen reader users. The save message usually goes away if I start editing other fields.
If you have to force focus to go back somewhere after a DOM is recreated, you'll have to save where you were (cookie) and then get the save point and just call the focus() method on it.
Im trying to make a script for a game. Where I have to make just 2 clicks, but they are on different pages.
On page 1 I click on "Send"
javascript:document.getElementById('send').click();
When i click on that button, my page redirect to a "confirm" page. Where i need to click "Ok" button.
How can i do to click my first button and after redirect "auto click" the "Ok" button from the new page?
If you also own the second page, you can have the window.onload method check against the url, for example look for the query string ?clickthrough=true (which your first page redirects to) and if it exists simulate a click of the button.
E.g., first page redirects to /second?clickthrough=true, and your javascript on the second page checks the url like this:
if (window.location.href.split("?").slice(-1)[0] == "clickthrough=true")
// click the button
If you do not own the second page, then I'd hope there is no way to do this as it would suddenly open users to a whole host of vulnerabilities.
I am using Samson O's very nice Easy Responsive Tabs to Accordion plugin on an ASP.NET page. On Tab 2 I have a Search button that when clicked executes some code in a code-behind and returns the search results to the page. Everything works except that the page goes back to the first tab when it's finished running the code in the code-behind. I want it to stay on Tab 2. How can I achieve this?
I have tried calling a JavaScript function to simulate the click of Tab 2 ($('#mycharities').click();) from the OnClientClick event of the Search button and also as the last thing on the Search button click event in the code-behind. Both options run the JavaScript but the page still goes back to the first tab once finished.
Answer to your question lies in the script for this plugin :
//Active correct tab
$($respTabs.find('.resp-tab-item.' + options.tabidentify)[tabNum]).addClass('resp-tab- active').css({
'background-color': options.activetab_bg,
'border-color': options.active_border_color
});
If you notice it takes [tabNum] to set the active tab. So you need to figure out the last selected tab num and in your custom javascript function that you need to set the appropiate css class to that tab. Then u will have it selected after the postback.
Best yet try to submit using AJax. It easy and you can avoid hassles.
I Have a chrome extension, it click a button when the page is loaded.
$(document).ready(function(){
document.querySelectorAll("input[type='submit']")[0].click();
});
This works, the only problem is that the button is also on the next page. So it keeps pressing the button and the page keeps reloading, so it's in a loop.
How do I fix this?
One solution would be to refine your selector. Find an unique parent element for the page you're targeting and create a more specific selector.
Another solution would be to check the current page url or the referrer and see if it matches a certain pattern.
I am trying to see witch one i like best, Tiny MCE or CKEditor. The problem that i am getting is that i need to add a custom toolbar button (or extend the anchor button). Trying now to modify the advlink plugin to insert internal links from the CMS. So i modified the page link.htm and added one button next to the href field. This button opens up a small popup where the user can select an internal link in the CMS and then press insert. The small popup then uses javascript to send the result back to the link.htm page. The link is then inserted into the href field. My problem is that when i press insert on the link.htm page, it just reloads the page and nothing is inserted.
This is the javascript that i added to the link.htm page:
function ShowInternalLinks() {
window.open('InternalLink.aspx', 'InternalLink', 'toolbar=0,status=0,menubar=0,location=0,directories=0,resizable=0,scrollbar=0,width=400,height=200');
}
function InsertInternalLink(link) {
document.getElementById('href').value = '/1/?' + link;
}
Nothing fancy, just opens up my custom aspx page when the ShowInternalLink is clicked. Then when the user clicks on insert on that page, the page calls the javascript InsertInternalLink and then closes the small popup. Everything works when i run the page, the href gets the correct value from the popup page, but when i then press insert, the page just reloads and the href field resets itself.
Any ideas? (If i write in the URL in the href field, it works perfectly. Just doesn't work when i use my popup window)
Side question: Can this even be done easily in CKEditor?
The href field has an onchange listener that performs the following: selectByValue(this.form,'linklisthref',this.value);
Can you debug and see if this is being called. I'm thinking that it isn't, and this might be your problem.