Switch to Firefox browser using Selenium - macos

Firefox browser only launches on Dock on my Mac but active screen shown is still Eclipse.
How can the focus be shifted to Browser?
public class FirefoxFirst {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","/Users/varunnadimpalli/Downloads/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("https://google.com");
selenium :3.3.1
Mac:`10.12.1

Strange why it wouldn't swap focus to firefox, if it is not in focus but still open try
((JavascriptExecutor) webDriver).executeScript("window.focus();");
If it is minimized you can try going through the windows handles
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
See if that is able to bring the firefox window up.

Not sure whether this works. Try maximizing the browser,
driver.manage().window().maximize();
Also, don't forget to add implicit wait after initiating the browser.
Note - I don't have enough points to comment this. else i have commented instead of writing this as answer.

Related

Xamarin Android debugging: No compatible code running

Context
I am using VS 2017.3 to develop Xamarin.Forms application. I am trying to diagnose where and why an Exception occur on my code.
I can successfully deploy run and debug my application using the SDK Android Emulator (HAX x86).
However in case an Exception occur I can not see any information about the Exception, see attached picture, settings.
Question
Is this normal in Android debugging, or missing I something?
...and my build settings:
I wanted to expand on #Uraitz's answer because it helped me figure out the problem.
First, as he explains, you will want to add an event handler in your activity, as shown in the following code:
protected override void OnCreate(Bundle savedInstanceState)
{
...
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
...
}
private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
In my case I put a breakpoint inside CurrentDomainUnhandledException so I could inspect the exception.
However, even with that breakpoint in there, I ran my code and still got a confusing no-callstack error.
At this point I thought the solution wasn't working. In fact it is, but I had to click the Play (continue) button multiple times before my app would hit the breakpoint:
After clicking that button two times, I finally hit the breakpoint:
If you want to get the callstack in the debugger, you will have to dive in a few levels before it is available, but you can do so by looking at the event args parameter.
The moral of the story is - if you have added the event handler but you still aren't hitting the breakpoint (or seeing output) - keep clicking the Continue button!
Just continue, then look through the Output, it will show you the stack trace of the exception. It is a good idea to learn how to read through the log files to find information about exceptions.
You can subscribe on each platform main constructor to UnhandledException event this will give you more information about exception before break debug.
for example in Android:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
If you need each platform explanation ask for them :)
Deleting the bin and obj folders solved it in my case.
I got similar issue, after investigating, I just have to disable the Xamarin Inspector.
Ill just throw this in the mix.
I was getting a "No compatible code running" error when attempting to break on otherwise 'working' code.
After struggling with this I decided to go back to an older version of visual studio where it didn't happening.
This gave me the idea to reset my Exception settings, and then the issue went away.
Seemingly there are a number of handled exceptions that any given library might be throwing, and if you choose to break on a particular condition you may well see this.

JavaFX Native Bundle Splash Screen

I'm using the javafx-maven-plugin and IntelliJ IDEA on Windows 7.
I'm trying to get a splash screen to show while my JavaFX application boots up, like this:
I tried using the SplashScreen-Image manifest entry—and that works, but only if you click on the .jar—I'm deploying the application as a Native Bundle and so the user clicks an .exe (or a shortcut to an .exe) not the actual .jar.
When you click the .exe no splash screen is shown.
This SSCCE I made will help you help me.
If I'm deploying my app using the javafx-maven-plugin, (which, if I'm not mistaken, uses the JavaFX Packager Tool, which uses Inno Setup), how can I get a splash screen to show after the user clicks the .exe?
More Findings:
Looking at the installation directory, I find a .dll called runtime\bin\splashscreen.dll. Does that mean it can be done?
The native launcher does not respect that spash-screen, it is only when being invoked by the java-executable. As the native launcher is loading the JVM internally, this won't work.
I haven't found a proper way to get this working, not even with some preloaders. Maybe you can find this helpful: https://gist.github.com/FibreFoX/294012b16fa10519674b (please ignore the deltaspike-related stuff)
Copied code:
#Override
public void start(Stage primaryStage) throws Exception {
// due to the nature of preloader being ignored within native-package, show it here
SplashScreen splashScreen = new SplashScreen();
splashScreen.show(new Stage(StageStyle.TRANSPARENT));
// needed for callback
final SomeJavaFXClassWithCDI launcherThread = this;
// for splashscreen to be shown, its needed to delay everything else as parallel task/thread (it would block otherwise)
Task cdiTask = new Task<Void>() {
#Override
protected Void call() throws Exception {
// boot CDI after javaFX-splash (this will "halt" the application due to the work done by CDI-provider
bootCDI(launcherThread);
// push javaFX-work to javaFX-thread
Platform.runLater(() -> {
primaryStage.setTitle("Some Title");
// TODO prepare your stage here !
// smooth fade-out of slashscreen
splashScreen.fadeOut((ActionEvent event) -> {
primaryStage.show();
splashScreen.hide();
});
});
return null;
}
};
// run task
new Thread(cdiTask).start();
}
In short: I'm creating my splashscreen myself.
Disclaimer: I'm the maintainer of the javafx-maven-plugin

WebDriver click() worked in Firefox 28+windows 7 is not working on Firefox28+windows 8

When i execute a program with below code snippet, click on a link worked fine on Windows7+Firefox28, but not on Windows8+Firefox28.
page navigated to Flipkart, searched for Samsung S3 but not clicking on the selected item to open its specifications, etc.
It is observed that the print line after click is executed.
public static void main(String[] args) {
WebDriver d = new FirefoxDriver();
d.manage().window().maximize();
d.get("http://www.flipkart.com/");
d.findElement(By.xpath(".//*[#id='fk-top-search-box']")).sendKeys("Samsung s3");
d.findElement(By.xpath(".//*[#id='fk-header-search-form']/div/div/div[2]/input[1]")).click();
//below is the line where, click which doesn't run on windows8+firefox28
d.findElement(By.xpath(".//*[#id='products']/div/div/div/div/div/a[contains(.,'Samsung Galaxy S3 (Marble White')]")).click();
System.out.println("After clicking on selected item...");
}
In some cases, click() does not work directly. In those cases, you can try on using sendkeys method.
driver.findElement(By.xpath("blah")).sendKeys(Keys.ENTER);
I am not sure of the reason, but it works when click does not work.

Selenium Web Driver Cancelling Firefox Downloads

I'm trying to cancel the pop up download windows in Firefox with selenium. I can switch windows and close alert windows, but I can't seem to select the download window. Any ideas?
Looking around, it seems Selenium RC can't do handle the download window because they depend on the OS. However, is this problem the same for the Selenium Web Driver? I know a solution to this can be done with autoit, but I'd like to keep it all in Java selenium if possible. Thanks.
WebDriver cannot directly interact with dialog windows this is because dialog windows are the domain of the operating system and not the webpage. However its possible to do actions on dialog windows using
SendKeys class method SendWait() of name space System.Windows.Forms
using System.Windows.Forms;
In the example code below a PLUpload button is pressed, which opens a Windows Dialog to select the file to upload.
Following lines are written to send key values to the dialog window displayed.
SendKeys.SendWait(#"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
SendKeys.SendWait(#"{Enter}");
Detailed reference of SendKeys class in C# can be found in http://msdn.microsoft.com/en-au/library/system.windows.forms.sendkeys.aspx
using System;
using System.Windows.Forms;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Interactions;
using NUnit.Framework;
namespace BusinessCreation
{
class PlUpload
{
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.plupload.com/example_queuewidget.php");
driver.FindElement(By.XPath("//object[#data='/plupload/js/plupload.flash.swf']")).Click();
SendKeys.SendWait(#"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
SendKeys.SendWait(#"{Enter}");
}
}
}

Webdriver - open browser on full screen

I use Webdriver remotely with firefox.
I want to open my browser on full screen. The browser is opened on full screen, but immediately minimize and moves to other program which open on my OS. When I run my webdriver locally, the broser is opened on full screen, and doesn't minimize (it stays in the browser, and doesn't move to other program). I want that my browser would open on full screen, and stay in the browser, even if I run my test remottley.
The reason is that I used Java Robot, and I have to be in the browser in order that my action would be performed.
Thank you.
I don't know I really understood your question, but have a look at
driver.manage().window().maximize();
https://technicaltesting.wordpress.com/category/webdriver/#3
Especially handy when combining Sikuli and WebDriver, you need to be absolutely sure that as much as possible is visible on the screen.
1
((FirefoxDriver)driver).getKeyboard().pressKey(Keys.F11);
If you want to hide the header, please add this in the code.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.fullscreen.autohide",true);
profile.setPreference("browser.fullscreen.animateUp",0);
WebDriver driver = new FirefoxDriver(profile);
((FirefoxDriver)driver).getKeyboard().pressKey(Keys.F11);
driver.manage().window().setSize(new Dimension(1024, 768));
((JavascriptExecutor)driver).executeScript("window.focus()");
Robot robot;
try {
robot = new Robot();
robot.mouseMove(300,300);
robot.mouseMove(250,300);
} catch (AWTException e1) {
e1.printStackTrace();
}
Try this instead:
driver.manage().window().maximize();
((JavascriptExecutor) driver).executeScript("window.focus();");
In Python, you can do something like this. Make sure you use latest Selenium package.
driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(30)
in 2022:
from selenium import webdriver
f = webdriver.Firefox()
f.get('https://duckduckgo.com')
f.fullscreen_window()
I stumbled upon the same problem, but I found #Chen 's F11 profile not reliable enough, so I came up with my own solution: by simply making the browser window larger than the screen so the actual content matches up perfectly with the size of the screen.
WebDriver driver = new FirefoxDriver();
java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Window window = driver.manage().window();
window.setPosition(new Point(-7, -87));
window.setSize(new Dimension((int) screenSize.getWidth() + 14, (int) screenSize.getHeight() + 94));

Resources