How to click Browser back button in Safari using selenium/javascript - selenium

I am using selenium automation in Safari. It seems there is an issue in using driver.navigate.back()
So I used:
((JavascriptExecutor)driver).executeScript("history.back")
((JavascriptExecutor)driver).executeScript("history.go(-1)")
But this code is going to the previous page and not actually clicking the browser back button. I confirmed by doing manually. If I do manually in my application, it will pop up a dialog saying "do you want to leave this page?" But with this code it's not happening.

Based on this open issue, it seems Safari reloads an old page. It doesn't fully initialize the extension for the page.
Hence Selenium does not support it:
safaridriver.inject.commands.unsupportedHistoryNavigation = function() {
throw Error('Yikes! Safari history navigation does not work. We can ' +
'go forward or back, but once we do, we can no longer ' +
'communicate with the page...');
};

Related

getWindowHandles not working properly with latest edge browser version

I am working on an application which supports only Edge Browser.
The login functionality works as follows -
On the login screen, when username and password values are provided and login button is clicked, a new browser window opens with an active alert pop-up saying Login Successful along with OK button similar to the image below -
Also, when this new window opens, the old browser window goes blank.
When user clicks on this OK button (or hits ENTER button on keyboard), user home page loads on this new browser window itself and the old window remains black throughout the session.
Automation -
To handle this flow in automation, I have used getWindowHandles() method where I get the handle of this newly opened window and accept the alert.
This used to work properly till edge browser version 105.
However, when the edge browser version was upgraded to 107, I started facing the issue where the getWindowHandles() method goes into infinite loop and eventually the test times out.
I also tried to simulate ENTER button hit by using Robot class but it made no difference.
I have tried using the edge-driver version matching with the current browser version 107 but the issue persists.
Can someone please let me know what can be done for this? Is these any known issue with newer edge browser version?
Thanks in advance..!!
This is the code written to handle multiple windows and the test times out at getWindowHandles() method itself.
for(String wh : driver.getWindowHandles()){
driver.switchTo().window(wh);
}
Adding a Wait may be the key to this problem:
WebDriverWait wait = new WebDriverWait(driver,20);
BTW, I've tested in Edge 108 (also with Edge Driver 108). There's no such error message and everything works great. You can upgrade to 108 and see whether this issue has been fixed.

How can I fix a button that is clicked but does not perform any actions?

So I'm currently working on a new project and I need to write some automated tests.
I came across a problem and I don't know how to fix it. If the button of my web page is clicked running selenium it doesn't perform any actions, but if I open the web page manualy and click on the button, everything works fine.
NOTE: I'm completely sure that the xpath is correct and the button is being clicked...
This is what happens running with selenium:
And this is what happens openning the web page manually and clicking on the button:

What is going wrong with kendo upload cancel?

I am seeing a very odd thing happen with kendo UI's kendoUpload. I have implemented a custom UI for displaying the files being uploaded, along with a progress bar and a cancel button. Kendo does not offer an API for cancelling uploads, but I read here that you can tap into kendo's default upload progress display to cancel an upload. That is exactly what I did, with the following javascript function attached to my custom cancel button:
var fileName = _getFileNameForThisCancelButton();
var kendoUpload = $('#file_upload').data('kendoUpload');
if (kendoUpload) {
var cancelButton = kendoUpload.wrapper.find('ul.k-upload-files')
.find('.k-file:has([title="' + fileName + '"]) .k-cancel');
cancelButton.click();
}
This little function works as far as it does fire the kendoUpload's cancel event, and the network traffic stops, so data is apparently no longer being sent from the browser to the server.
However, as soon as one cancel button is clicked, any subsequent requests to the site from the browser where the cancel button was clicked hang forever. Note this is for the entire site, not just the file upload page, and only for the browser in question -- the site still loads in other browsers where upload cancel buttons have not been clicked. This goes for Chrome 30.0.1599.69 m, Firefox 20.0, and IE8.
With Firefox and IE, simply closing and restarting the browser causes the hanging to stop, and the site loads again. With Chrome I have found this doesn't work, and neither does logging out of my local machine -- I have to do a full reboot to get the site to load again in Chrome. I think this may have something to do with my Chrome settings though. I have it set up to load all of my last tabs when re-opening, and I have noticed that closing and re-opening Chrome also does not delete my login cookie for the site. Either way, It's the same issue even if it is harder to reset in Chrome.
So... any ideas what is going on here? It seems almost as if the browsers are still waiting for a response from the server for the cancelled upload and blocking on the entire site waiting for a response that will never be delivered.
Updates
Turns out I was right about Chrome. After disabling the "Continue where I left off" startup option, Chrome now behaves the same as FF and IE -- need to close and reopen the browser to get the site to load again.
I have also tried this without the custom UI, meaning I turned off showFileList: false when creating the widget and clicked the actual cancel button. Starting to wonder if this has anything to do with the POST method on the server...?

IE9 Automation of Button Click

Several of my vendor's require me to place orders thru their websites. I have automated the process by clicking on a button in my order processing program. My program will open the default browser (now IE 9 after my previous computer died), navigate to the vendor's website order page, fill out the information fields, and then click the form submit button.
this.oIE.Document.all.ctl00_MainContent_Login1_LoginButton.click()
or
this.oIE.Document.getElementById("ctl00_MainContent_Login1_LoginButton").click()
The problem appears to occur only when the button has an "onclick" value.
In IE8, the click() event executes the onclick code. In IE9, the click event returns a generic object. It does not fire the onclick code.
I have tried x.FireEvent("click"), but this returns an object as well. It appears that IE9 DOM onclick values cannot be executed by external programs.
My program works fine on IE8 (I use Chrome, IE, FireFox with different settings and logins, so changing the default browser is not really an option. Also, some of my vendors demand that I use IE as their sites are broken on the other browsers.)
Any advice on a permanent fix for this would be appreciated.
I could have written your question verbatim, and have been fighting this for as long as you have.
Stupid, stupid problem: The click() function now requires a parameter: click(1)
w = this.oIE.Document
z = w.getElementById("btn-header-input-signin")
z.click(1)
Haven't thoroughly tested this, but it works on the US Postal Service login page.
The function that the button click calls will presumably have the same name on each browser. Can you call that function instead?
Simulating the button click seems an unnecessary step. Also, have you tried jQuery? Libraries like that try to smooth away browser differences.

Safari - How To Automate The Reset Safari Items

Using Safari browser and finding one hurdle to making it my default browser - there is no default setting for clearing/deleting all the stuff you find in the menu's Reset Safari panel.
I made an Automator routine using the 'Watch Me' to do this and quit safari - it works. But, I'd really like to not have the steps display while it's running. The show actions is not selected but, they still show.
I tried creating a script but Safari dictionary does not have the option for Reset (or any of the reset panels items...)
So, how can I accomplish this?