I need to click on a cancel button for a Java based application.
I am using IE Driver, Eclipse IDE and my application only supports IE.[i am scripting in Java]
Here is the situation,
Login to the application
There is a account session popup[confirmation box][js]
[The alert has the focus, user cannot focus the application]
Click on the cancel button
Now, i have logged in successfully but i am unable to handle the JS Alert window.So i am unable to write further scripts.
Kindly help me out !!!
If you're using Java, and you're using the Selenium WebDriver API, something like the following code should work:
driver.switchTo().alert().dismiss();
Alert handling has not been implemented for every driver, but it should work for IE.
Remember you can always find the Javadocs for the WebDriver API at this link.
To Handle Alert in IE, you need to set the capabalities for IE first:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability("ignoreProtectedModeSettings", true); //added this to ignore protecion mode setting so as to launch IE
driver = new InternetExplorerDriver(capabilities);
driver.get("url");
driver.switchTo().alert().dismiss(); //or
driver.switchTo().alert().Accept(); // accordingly
Related
I am trying to find a way that enables me to hide the driver (bot) of the selenium in VBA during the execution of the code and display it at end
I can hide it using this line
bot.AddArgument "--headless"
But how I restore it?
No, it won't be possible to make Chrome operate initially in headless mode and then switch back to normal mode within the same session.
When you configure an instance of a WebDriver with Options() to span a new Browsing Context the configuration gets baked within the driver executable which will persist for the lifetime of the WebDriver and being uneditable. So you can't modify/add any existing/new configuration through Options() class to the WebDriver instance which is currently in execution.
Even if you are able to extract the Driver and Session attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated Driver and Browsing Session still you won't be able to change the set of attributes of the Driver.
You can find more details in these discussions:
How to set selenium webdriver from headless mode to normal mode within the same session?
Change ChromeOptions in an existing webdriver
How do I make Chrome Headless after I login manually
Credits to undetected Selenium
I am trying to integrate Lighthouse in my Selenium scripts
Basically each time my script lands on new page I should click on the Lighthouse extension and generate a report.
What I could Achieve: (sample working code at the end)
Setting up desired capabilities to launch Chrome with Lighthouse extension added
What I am unable to do:
I want to use the added
While on the desired web page
Click on Chrome Extension button and select Lighthouse extension
In the Lighthouse extension pop up displayed Click on "Generate Report" button
Sample working code:
System.setProperty("webdriver.chrome.driver","C:\\Users\\v744536\\Downloads\\chromedriver_win32\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addExtensions(new File("C:\\Users\\v744536\\eclipse-workspace\\AccessibilityProject\\LH.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability(ChromeOptions.CAPABILITY, opt);
#SuppressWarnings("deprecation")
ChromeDriver driver = new ChromeDriver(capabilities);
driver.get("https://www.google.com");
I should tell you that the Lighthouse browser extension simply calls the PSI API, which is free and easy to use directly: https://developers.google.com/speed/docs/insights/v5/get-started
The extension directs you to a page, and that page will use the PSI API. If you don't want to use the PSI API directly, another option is to just open the Lighthouse Viewer with the url you want:
https://googlechrome.github.io/lighthouse/viewer/?psiurl=https://www.example.com
That's all the extension is doing under the hood. This would be much simpler than via scripting user interactions.
Source: I work on Lighthouse.
I am testing web application. In my test I check client data. For use this test I need IE Tab in chromedriver. I'm initializing chromedriver with IETab correctly. After that page is display with below popup
With popup in console I see below log:
Uncaught IETABAPI Error: Permission not granted. You must call window.ietab.requestAccess to use the IE Tab Api.
I clik Allow and nothing's gonna happen. Correctly test should opening new bookmark in chromedriver. Below my code which is executing chromedriver with IETab.
default void ChromeExtensionIETab() {
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("C:\\Users\\user\\Dysk Google\\all\\testowanie\\chromedriver_win32\\extension_12_4_4_1.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
options.addArguments("--use-fake-ui-for-media-stream");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Dysk Google\\all\\testowanie\\chromedriver_win32\\chromedriver.exe");
setDriver(new ChromeDriver(options));
getDriver().get("https://api-test/");
getDriver().manage().window().maximize();
getDriver().manage().timeouts().implicitlyWait(18, TimeUnit.SECONDS);
}
Can someone explain me what should I do?
The Enterprise version of IE Tab includes permissions that would otherwise have to be manually enabled by your end users. Read more here.
If IE Tab is installed:
Click here to allow IE Tab to access https:// URLs and file downloads
Enterprise customers please contact us at support#ietab.net to discover how to deploy these settings automatically.
What we don't see is the web page that you are "driving".
The pop-up you are seeing is from the IE Tab api which must first call window.ietab.requestAccess and wait for the result before calling window.ietab.openWithIETab.
The error you are seeing is because the page called window.ietab.openWithIETab without waiting for a response form requestAccess.
So the web-page is probably calling both calls without waiting for the result from requestAccess, perhaps because the developer had already allowed access so they aren't aware that this pop-up is showing any more.
I am automating the application using selenium which is enabled with SSO(VIDM) integration which will take my system domain name and password. The moment I hit the application URL, It will process the SSO(VIDM) and displaying the browser pop up with SSL certificate , OK button. I am unable to locate "OK" button as inspect is blocked for that pop up.
Manual Work Around noticed: Able to select that certificate from the pop up with out clicking okay button by placing the cursor in Chrome driver address bar and then perform enter using the system keyboard.Please see the image here
Add the below chromedriver option to launch specific profile.
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
ChromeDriver driver = new ChromeDriver(options);
Refer to chromedriver page for more information.
ChromeDriver Capabilities
Given that Selenium 2 closes the devtools window which contains my emulator profile saved under my user profile for chrome. Is there a way to trigger devtools to open using a selenium script?
Here is the info on the devtools window closing issue
https://sites.google.com/a/chromium.org/chromedriver/help/devtools-window-keeps-closing
I feel a little exhausted trying some of these Chromium override parameters only one of which seems to work
http://peter.sh/experiments/chromium-command-line-switches/
The one that had any affect is the following
options.addArguments("user-data-dir=/Path/to/chrome/profile");
If there is no way to open the dev tools window or panel, is there a way to initialize the emulator?
at the terminal, type the following -
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --auto-open-devtools-for-tabs
You can use Robot class for same. It just going to help you to open dev-tools on any browser.
Use this code on the place you want to open dev-tools
try{
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_F12);
robot.keyRelease(KeyEvent.VK_F12);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
You can used below given code, it is working fine with FireFox just change the browser
public void open(String url) {
driver.get(url);
Actions action = new Actions(driver);
String pressF12=Keys.chord(Keys.F12,"");
driver.findElement(By.id("lst-ib")).sendKeys(pressF12);
}
As the same link you provided says, it's not possible to use ChromeDev tools with Selenium's ChromeDriver since 2.x. It's simply in direct conflict, you could use either one or the other.
The only way to perform a workaround is to pause all chrome driver interactivity, launch the DevTool's through some other automation framework such as Robots API, do whatever you need, and continue.
But I might think on what I need from dev tools, isn't there an alternative to what you need by providing Chrome with the proper configuration on launch? (loading a different profile, or loading an emulated device)
Why do you need the chrome devtools anyway?
Is it for monitoring the network traffic? Why not usefirefoxdriver with firebug.xpi or browsermobproxy.
To open a page in emulated device's browser. This can be done with chrome, without opening the devtools.
WebDriver with chrome emulated browser
This is a code snippet that you can use to fire up chrome browser in a particular emulate version. Note the key thing here is the deviceName value, which should match as it is mentioned in the chrome browser of yours.
public static WebDriver MobileOpen()
{
Map<String, String> mobileEmulation = new HashMap<String, String>();
System.setProperty("webdriver.chrome.driver","path/to/chromedriver");
mobileEmulation.put("deviceName", "Google Nexus 6");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);
return driver;
}
Hope this helps.
Edit: I just saw it is a 3 years old post. The guy probably has found his way home. :P
Have you tried the console API for your needs? It will allow you to invoke some dev-tool functions from inside JS.