Start safari with extension using safariDriver in selenium - selenium

I want to start my browser with my extensions. In chrome I can use the chromeOptions as in code sample below. Firefox works in a similar way.
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
However in Safari there is no addExtensions method. What is the correct way to do this with Safari?

This might help.
https://github.com/SeleniumHQ/selenium/wiki/SafariDriver
I found that if you want to open another safari extension inside safari, you have to do it from the safari browser itself.
https://github.com/SeleniumHQ/selenium/wiki/SafariDriver-Internals#building-the-safaridriver
So basically:
Sign up for Apple's (free) Safari Developer Program and generate a
signed certificate for the extension.
Build the SafariDriver extension: $ ./go safari
Install the extension:
Launch Safari
Enable the Develop menu (Preferences > Advanced > Show Develop menu in menu
bar)
Open the Extension Builder (Develop > Show Extension Builder)
Add a new extension: $SELENIUM_CLIENT/build/javascript/safari-driver/SafariDriver.safariextension
Click Install

Which version of Selenium are you using? It looks like they added safariOptions.addExtensions(".."); in June of 2013.
SafariOptions options = new SafariOptions();
options.addExtensions(new File("path/to/extension.safariextz"));
WebDriver driver = new SafariDriver(options);

The Apple-maintained safaridriver implementation does not support configuring extensions via WebDriver capabilities or other automated means. If you feel that this is an important feature worth doing, please file an enhancement request at https://bugreport.apple.com/ with more details of your use case.

SafariDriver is a class in the org.openqa.selenium.safari package is used to access safari browser
WebDriver driver = new SafariDriver();
driver.get("https://stackoverflow.com");

Related

Using webdriver plugin in jmeter

Iam trying to use webdriver plugin to automate an application in jmeter. Can anyone help me to do scripting in selenium by using webdriver plugin. Thanks in advance.
It depends on the browser and programming language you're using.
Currently Chrome is the most popular browser and JavaScript is the default language for the WebDriver Sampler so:
Download chromedriver (make sure that the version you download matches your Chrome browser version)
Add Chrome Driver Config and specify the path to the chromedriver in the "Chrome" tab:
Add WebDriver Sampler and implement the code for your test scenario. WDS.browser will stand for the ChromeDriver instance so you will be able to: use
WDS.browser.get('some url') - open a page
var element = WDS.browser.findElement(org.openqa.selenium.By.id('some id')) - locate a WebElement
element.click() - click the element found in the previous step
etc.
More information: The WebDriver Sampler: Your Top 10 Questions Answered

How to click chrome extension using selenium webdriver java?

I am able to load a chrome extension through CRX file and successfully add it to the chrome with selenium webdriver using java with Chrome Options, can anyone tell me how to automate to click the extension once it added to the chrome.
Every time i have to click manually on the extension for the further process of automation.
Not sure how you are doing it. Try loading the extension using ChromeOptions, it loads the browser with extension and there is no need to click any button manually
ChromeOptions options = new ChromeOptions();
//Adding Chrome extension
options.addExtensions(new File("Chrome extension - crx file path"));
options.addArguments("--start-maximized");
options.addArguments("--test-type");
System.setProperty("webdriver.chrome.driver", "path to/chromedriver.exe");
driver = new ChromeDriver(options);
Just FYI - handling OS level controls is out of reach of Selenium.
To handle OS level controls you can use AutoIT or LDTP.
Personally I prefer LDTP for smaller interaction as it gives seamless experience and is platform independent - https://github.com/ldtp/cobra
You can also try Pywinauto, a python library. With pywinauto you write the code to handle the OS level control and call this python script from Java code. For most of the tools you need to install their executables but for Pywinauto you only need Python to be installed which is approved to use in most of the organizations. For basic pywinauto script you need not learn the language.
Refer https://pywinauto.readthedocs.io/en/latest/

Using Selenium on iPad?

I use a selenium application, and I make test on my computers browsers. It opens and manage the browsers.
Would there be a way to simulate an iPad and run this same code on it? Same thing for a cellphone?
So far I found people who wrote they did so by emulation but did not say how...
I execute iPad testing via emulation using ChromeDriver. Does this help? With C#:
IWebDriver driver;
ChromeOptions ipadOptions = new ChromeOptions();
string deviceName = "Apple iPad";
ipadOptions.EnableMobileEmulation(deviceName);
driver = new ChromeDriver(ipadOptions);
My biggest struggle was testing requirements depending on orientation (landscape vs. portrait.) It doesn't support switching orientation which is ridiculous.
To be able to use selenium code with Android device browser, try following:
install Android SDK on your computer to get access to Android Debug Bridge (adb) features
start adb server from cmd/Terminal with "adb start-server" command
(target device should be already connected)
start in the same way chromedriver server with "chromedriver" command (chromedriver executable should be already in your system Path)
you should see something like:
Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515(in my case it always starts on 9515 port, but you have to check this value to use it in next step)
run code with 'androidPackage':com.android.chrome' chromeOptions and instance of remote webdriver. Python code looks like:
from selenium import webdriver
capabilities = {'chromeOptions': {'androidPackage':com.android.chrome',}}
driver = webdriver.Remote('http://localhost:9515', capabilities) # 9515 is mentioned port number on which chromedriver server started
driver.get('http://google.com')
driver.quit()
P.S. It's not a direct answer on question how to use selenium with iPad, but OP asks for selenium + Android also

how to use different version of firefox using webdriver?

how to set Firefox version in web-driver?
I just want to user different version of Firefox.
like different version 19, 20 , 21....
please provide a generic solution which help for other browser also.
You have to install all the versions on your system. Then you can use the System property webdriver.firefox.bin to define the path for Firefox. Note than since the path is set through a System property, you will not be able to run two different Firefox in the same Java process.
This solution is specific to Firefox. There is no generic solution. You have to configure every WebDriver yourself.
More information about the configuration of Firefox Web Drvier.
Finally i have found solution to run with different browser version
System.setProperty("webdriver.firefox.bin", "/Applications/Firefox-2.app/Contents/MacOS/firefox-bin");
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
System.out.println(driver.getTitle());
driver.close();
driver.quit();
I have found how to start a different FireFox browser (actually WaterFox) in Python Selenium, replacing
driver = webdriver.Firefox()
with
driver = webdriver.Firefox(firefox_binary = "/path/to/my/waterfox")
(Ubuntu 20.04, Python 3.95)

Robot Framework browser support

Has the robot framework support for IExplorer or only for Firefox and Chrome?
(If yes, how to configure it?)
Thanks!
Robot Framework does not, in itself, support any particular browser, so I am guessing you are referring to either SeleniumLibrary or Selenium2Library which use selenium and selenium 2 respectively. The browser support of these is well documented at seleniumhq and there is much support out there. It is recommended for new projects to use Selenium2Library as this will receive ongoing support.
Please check the driver compatiblity for browser.
You might have already known of IE driver.
Apart from that you also need to check Python version- Selenium2 version - IE Driver version - IE browser version compatibility.
In addition to #theheadofabroom 's answer, I should add that Internet Explorer does not play well with Robot Framework. Your test might not work for any number of reasons on IE while it may work just fine on FireFox and Chrome, but the most common is timing. IE is just slow enough that when Robot Framework goes to click on the next element, it searches the page for it, but it hasn't loaded in yet. As long as you have the Selenium webdriver for IE installed correctly and have written your Robot Framework code correctly, I'd recommend adding some Sleep keywords between actions to slow your code down and increase the probability that the element you want to click will load before Robot Framework searches the page for it. This is especially true if you're writing for Chrome and want to send it to either Firefox or IE.
Open Browser ${WEBAPPURL} ${BROWSER} is the keyword to open the browser.
For Firefox you can use firefox/ff instead of ${BROWSER}
For Google Chrome you can use googlechrome/gc/chrome instead of ${BROWSER}
For Internet Explorer you can use internetexplorer/ie instead of
${BROWSER}
For Firefox you don't need any driver but IE and Chrome you need to install the drivers
You can find the installers in and info here for Chrome and here for IE
Download IEdriver exe from here and put this exe file in Scripts folder of your Python installation directory. For eg, in my case it is C:\Python27\Scripts.
Ride will now launch IE for you.
Robot class supports keyboard inputs regardless of the browser. It is a class from the java.awt package and not specific to any browser. It is used in automation for performing operations on the web browser(stand alone application) in which a web-page is being automated
Note that it cannot perform operations directly on the web browser as it's a stand alone application, but can make use of keyboard shortcuts to indirectly perform the operation.
For example, if you want to open a new tab in a browser, you can use the Robot class to press Ctrl+t instead of trying to click on the new tab.
Code to use it to open a new tab in your program
Webdriver driver = new ChromeDriver(); //FirefoxDriver(), IntrrnetExplorerDriver();
driver.get("......");
//code goes here
//to open a new tab
Robot rob = new Robot();
rob.keyPress(Keys.VK_CTRL);
rob.keyPress(Keys.VK_t);
rob.keyRelease(Keys.VK_CTRL);
rob.keyRelease(Keys.VK_t);
//itetator to switch between the tabs