Selenium Interview Questions

Selenium is one of the top techs that everyone should learn in upcoming years. Its share value is eventually increasing, and lot opportunities are available for freshers and experienced candidates in the top reputed companies. 

So if you are preparing for a Selenium Interview then you’re at the right place, our experts compiled Top 50 Selenium Interview Questions and Answers for freshers and experienced. This blog covered all topics from basic to advanced Selenium Interview Questions and answers that help you to crack the interview and acquire your dream job with a decent package. 

 Categories of Selenium Interview Questions

Here Are The Selenium Interview Questions And Answers.

Q1) What is meant by Automation Tool?

Ans: Automation testing utilizes automation tools to execute and write test cases, and no manual association is essential for implementing an automated test suite. Analyzers prefer automation tools to create test cases and scripts and after bunch into test suites. 

Automation testing empowers the utilization of specific tools to automate manually composed test cases without any human interference. Automation testing tools can get to the test information, manages the execution of tests and looks at the real outcome against the expected result. 

Q2) List out commonly used automation testing tools for functional automation?

Ans: Following are some of the commonly used automation testing tools: 

  • Selenium, provided by Open Source.

  • Coded UI, provided by Microsoft

  • Rational Robot, provided by IBM

  • Quick Test Professional, provided by HP

  • Auto it, provided by Open Source. 

Q3) Explain the benefits of Automation Testing?

Ans: Following are the benefits of Automation testing: 

  • Save money and time. Automation testing is quicker in execution. 

  • Reusability of code. Generate code one time and execute numerous times with low maintenance. 

  • Simple reporting. It produces automatic reports after the test implementation. 

  • Simple for compatibility testing. It empowers equal execution in the blend of various OS and browser circumstances. 

  • Ease support. It is less expensive compared with manual testing a while ago. 

  • Automated testing is more reliable. 

  • Automation testing is adaptable and more powerful. Automation tools permit us to coordinate with Github, Jenkins, Cross Browser Testing Tools, and many more. 

  • It is generally utilized for relapse testing. It helps to execute repeated test cases. 

  • Insignificant manual intervention. Test scripts can be run ignored. 

  • Maximum coverage. It assists in expanding the test case.

 Q4) List out commonly used automation tools for non-functional automation?

Ans: Following tools are commonly used for non-functional automation:  

  • JMeter, provided by Apache.

  • Acunetix, provided by Acunetix.

  • Load Runner, provided by Hp.

  • Burp Suite, provided by PortSwigger.

Q5) Explain about a selenium tool?

Ans: Selenium is a powerful open-source automation tool for web application testing (even we can say acceptance testing for the web application), allowing you to automate activities like — click, the selection from the drop-down type, and many more for the website page. It is mainly created in JavaScript and portal advancements, such as frames and DHTML, hence it supports all major browser platforms

Q6) List out the programming languages, operating systems, and browsers that support Selenium?

Ans: Selenium support various programming languages, operating systems, and browsers: Following is the list: 

  • Programming Languages: JavaScript, Python, Php, Ruby, Java, C#, Perl
  • Operating System: Windows, iOS, Mac, Linux, Android, Solaris
  • Browsers: Opera, Google Chrome, Internet Explorer, Mozilla Firefox, Safari, Edge. 

Q7) Who developed Selenium and why?

Ans: Jason Huggins and group developed this tool in 2004 when working for Thought work (IT rethinking organization). They made this tool to test expenses and internal time of the application, which is written in (python).

Q8) List out the Selenium components?

Ans:   

  • Selenium Integrated Development Environment (IDE) – Selenium IDE is a playback and record tool. It is conveyed as a Firefox Plugin. 
  • Selenium Remote Control (RC) – Selenium RC is a server that permits a client to make test scripts in the aspired programming language. It also permits executing test scripts inside the enormous range of browsers. 
  • Selenium WebDriver: WebDriver is an alternate tool that has different preferences over Selenium RC. WebDriver instantly communicates with the internet browser and utilizes its local similarity to automate. 
  • Selenium Grid: Selenium Grid is utilized to circulate your test execution on numerous stages and conditions simultaneously.

Q9) List out a set of tools that are available in Selenium?

Ans: Selenium has four tools — Selenium IDE, Selenium Grid, Selenium 1.0 (Selenium RC), and Selenium 2.0 (WebDriver). Selenium Core is another tool, but it is not used in isolation since it is available as part of Selenium 1.0 and Selenium IDE.

Inclined to build a profession in Selenium? Then here is the blog post on, explore Selenium Training

Q10) What is Selenium 1.0?

Ans: Selenium 1.0 or Selenium Remote Control (famously known as Selenium RC) is a library accessible in various languages. The essential purpose behind the coming of Selenium RC was the inadequacy of Selenium IDE to perform tests in browsers other than Selenium IDE and the programmatic restrictions of language Selenese utilized in Selenium IDE.

Q11) What is Selenium 2.0?

Ans: Selenium 2.0, known as WebDriver is the most advanced of Selenium 1.0. It gives a preferable API over Selenium 1.0 doesn't experience the ill effects of Java content security limitation which Selenium 1.0 backs more UI complicated UI tasks like drop and drag.

Q12) Explain about Selenium IDE?

Ans: Selenium IDE is a Firefox plug-in (by and large)used to replay and record the Firefox browser test. Selenium IDE can operate only with the Firefox browser.

Q13) Tell which language is used in Selenium IDE?

Ans: Selenium IDE utilises an html sort of language called Selenese. Though cannot use other languages (Java, c#, PHP, etc.) with Selenium IDE, Selenium IDE lets you transform test in these languages so they could use them with Selenium 1.0 or Selenium 2.0

Q14) Give a brief description of Selenese?

Ans: Selenium IDE is achieved as a Firefox extension, which gives playback and record functionality on test scripts. It permits analyzers to send out recorded scripts in numerous languages like Ruby, Python, Java, HTML, C#, TestNG and JUnit. 

Selenium IDE has a defined scope, and the provided test scripts are not portable, and robust.

Q15) Explain about Selenium Grid?

Ans: Selenium grid allows you to convey your tests on different machines and all one of them simultaneously. Subsequently, you can execute tests on IE on Windows and Safari on Mac machines utilizing a similar test content (indeed, quite often). This helps in diminishing the hour of test execution and gives speedy input to stakeholders. Helps in lessening the hour of test execution and gives fast criticism to stakeholders.

Q16) Explain different types of locators in Selenium?

Ans: The locator can be named as a location that recognizes a web component extraordinarily inside the page. Accordingly, to distinguish web components precisely and exactly we have various sorts of locators in Selenium:

  • ID

  • ClassName

  • Name

  • TagName

  • link text

  • PartialLinkText

  • Xpath

  • CSS Selector

  • DOM

Selenium Tutorials

Q17) List out some of the test types that are supported by Selenium?

Ans: Following are some of the test types that are supported by Selenium:

  • Sanity Testing

  • Regression Testing

  • Functional Testing

  • UI testing (black box)

  • Cross Browser Testing

  • Smoke Testing

  • Responsive Testing

  • Integration Testing

Q18) List out different types of WebDriver APIs that are available in Selenium?

Ans: Following are the various types of WebDriver APIs that are available in Selenium: 

  • ChromeDriver

  • EventFiringWebDriver

  • HtmlUnitDriver

  • AndroidDriver

  • iPhoneDriver

  • RemoteWebDriver

  • FirefoxDriver

  • iPhoneSimulatorDriver

  • InternetExplorerDriver

Q19) How is Selenium different from commercial browser automation tools?

Ans: Selenium is a library accessible in an array of languages, for example, Java, C#, python, ruby, PHP and so forth. At the same time, most business instruments are restricted in their ability to utilize only one language. Moreover, many of those apparatuses have their exclusive language, which is of little use outside the area of those instruments. Most business instruments centre around the record and replay while Selenium accentuation on utilizing Selenium IDE (Selenium record and replay) device to get to know Selenium working and afterwards proceed onward to develop more Selenium libraries like Remote control (Selenium 1.0) and Web Driver (Selenium 2.o). 

Even though most business instruments have implicit capacities of a test was revealing, mistake recuperation systems and Selenium doesn't give any such highlights as a matter of course. Yet, given the rich arrangement of dialects accessible with Selenium, it is exceptionally simple to imitate such highlights.

Q20) What is an Accessor in Selenium?

Ans: An accessor is one of the kinds of Selenese. 

1. Accessors are utilized for putting away the estimation of an objective in a variable. 

Ex: 

a) store title — Stores the title of a window in a variable 

b) store text — Stores the objective component text in a variable 

2. Accessors are likewise utilized for assessing the outcome and putting away the outcome in a variable 

Ex: 

a) storeTextPresent — Evaluates whether the content is available in the current window. On the off chance that the content is available stores valid in the variable else stores bogus 

b) store element present — Evaluates whether the component is available in the current window. On the off chance that the element is available stores valid in the variable else stores bogus.

Q21) What are the two modes of views in Selenium IDE?

Ans: Selenium IDE can be opened either in the sidebar (View > Sidebar > Selenium IDE) or as a spring up window (Tools > Selenium IDE). While utilizing Selenium IDE in the program sidebar, it can't record client tasks in a spring up window opened by the application.

Q22) What verification points are available in Selenium?

Ans: There are mostly three types of verification points that are available with selenium :

  • Check for the page title.

  • Check for certain text.

  • Check for the certain element (textbox, drop-down, table etc.)

Q23) Explain the difference between verify and assert Commands?

Ans:  

Assert: Assert command checks if the given condition is valid or not. If the state is valid, the program control will execute the following phase of testing, and if the condition is not valid, execution will stop, and nothing will be executed. 

Confirm: Verify command checks if the given condition is valid or not. It doesn't end program execution, i.e., any failure during confirmation would not stop executing and executing all the test phases.

Q24) Explain about XPath?

Ans: XPath is likewise characterized as XML Path. It is a language used to query XML records. It is a significant way to deal with finding components in Selenium. XPath consists of a way of articulation alongside certain conditions. Here, we can undoubtedly compose XPath content/inquiry to find any element in the page. It is created to permit the route of XML records. While exploring, the key factors are choosing distinct components, characteristics, or some other piece of an XML record for precise preparing. It likewise delivers dependable finders. Some different focuses on XPath are as per the following. 

  • XPath is a language utilized for finding hubs in XML archives. 

  • XPath can be utilized as a substitute when you don't have a valid id or name quality for the component you need to find. 

XPath gives finding methodologies like: 

  • XPath Absolute 

  • XPath Attributes

Q25) Explain about XPath Attributes and XPath Absolute?

Ans: 

XPath Absolute:

  • XPath Absolute allows users to consider the complete XPath location from the root HTML tag to the specific components.

  • Syntax: //html/body/tag1[index]/tag2[index]/.../tagN[index]

  • Example: //html/body/div[2]/div/div[2]/div/div/div/fieldset/form/div[1]/input[1]

XPath Attributes:

  • XPath Attributes is always suggested when you don't have a suitable id or name attribute for the component you want to locate.

  • Syntax: //htmltag[@attribute1='value1' and @attribute2='value2']

  • Example: //input[@id='passwd' and @placeholder='password']

Basic Level Selenium Interview Questions and Answers:

Q26) What is the difference between Selenium 2.0 and Selenium 3.0?

Ans: Selenium 2.0 is a device that makes the improvement of automated tests for web applications simpler. It describes the consolidation of the first Selenium project with the WebDriver project. Selenium RC got belittled since the consolidation, be that as it may, was utilized for in reverse similarity. 

Selenium 3.0 is the all-encompassing form of Selenium 2.0. It is characteristically backwards compatible and doesn't include Selenium RC. The new model fixed a few bugs and expanded stability.

Q27) Explain various types of Web Locators?

Ans:  

Locator is a command that indicates to Selenium IDE which GUI components ( state Text Box, Buttons, Check Boxes, and so on) it needs to work on. Locator shows the region of activity. 

Locator by ID: It takes a string parameter estimation of the id characteristic that profits the item to findElement() technique. 

 driver.findElement(By.id("user")); 

Locator by the connection: If your focus on the component is a connection text, you can utilize the by.linkText finder to find that component. 

 driver.findElement(By.linkText("Today's deals")).click(); 

Locator by Partial connection: The objective connection can be found utilizing a text segment in a connection text component. 

 driver.findElement(By.linkText("Service")).click(); 

Locator by Name: It will restore the principal component with the name property estimation coordinating the area. 

 driver.findElement(By.name("books").click()); 

Locator by TagName: Locates all the components with the coordinating label name 

 driver.findElement(By.tagName("button").click()); 

Locator by class name: This discovers components dependent on the estimation of the CLASS property. On the off chance that a component has numerous classes, this will coordinate against every one of them. 

 driver.findElement(By.className("inputtext")); 

Locator by XPath: It takes a String boundary, an XPATHEXPRESSION and returns an item to findElement() strategy. 

 driver.findElement(By.xpath("//span[contains(text(),'an account')]")).getText(); 

Locator by CSS Selector: Locates components dependent on the driver's fundamental CSS selector motor. 

 driver.findElement(By.cssSelector("input#email")).sendKeys("myemail@email.com");

Q28) List out various types of navigation commands?

Ans: Following are the various types of navigation commands: 

  • driver.navigate().to("https://www.ebay.in/"); - Navigates to the gave URL 
  • driver.navigate().refresh(); - This technique refreshes the current page 
  • driver.navigate().forward(); - This strategy does operation as tapping on the Forward Button of any browser. It neither acknowledges nor brings anything back. 
  • driver.navigate().back(); - This technique does operation as tapping on the Back Button of any browser. It neither acknowledges nor brings anything back.

Q29) List out various types of waits that are supported by WebDriver?

Ans: 

  • Implicit - Implicit hang tight orders Selenium to hang tight for a specific measure of time before tossing a "No such component" exemption. 
  • driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS); 
  • Explicit wait: Explicit stand by is utilized to advise the Web Driver to hang tight for specific conditions before tossing an "ElementNotVisibleException" exemption. 
  • WebDriverWait wait= new WebDriverWait(WebDriver Reference, TimeOut); 
  • Fluent wait: It is utilized to advise the web driver to hang tight for a condition. Just as the recurrence, we need to check the condition before tossing an "ElementNotVisibleException" case. 
  • Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);

Q30) What is the difference between driver.quit() and driver.close()?

Ans: 

driver.close(): This command stops the browser’s current window. If various windows are open, the current window of focus will be closed.

driver.quit(): When quit() is called on the driver instance, and there are one or more browser windows open, it closes all the open browser windows.

Q31) How to click on a hyperlink in Selenium?

Ans: 

driver.findElement(By.linkText(“Today’s deals”)).click();

The command finds the component using link text and then clicks on that component, whereafter it would redirect the user to the corresponding page.

driver.findElement(By.partialLinkText(“Service”)).click();

The above command finds the component based on the parenthesis link's substring and thus partialLinkText() finds the web component. 

Q32) How to assert the title of a webpage?

Ans: 

Get the title of the webpage and store in a variable

    String actualTitle = driver.getTitle();

Type in the expected title

   String expectedTitle = “abcdefgh";

Verify if both of them are equal

   if(actualTitle.equalsIgnoreCase(expectedTitle))

   System.out.println("Title is Matched");

  else

  System.out.println("Title didn't match");

Or,

   Assert.assertEquals(actualTitle, expectedTitle);

Q33) How to scroll down a page using JavaScript?

Ans: 

scrollBy() method is used to scroll down the webpage

Syntax:

executeScript("window.scrollBy(x-pixels,y-pixels)");

First, create a JavaScript object

   JavascriptExecutor js = (JavascriptExecutor) driver;

Launch the desired application

   driver.get(“https://www.ebay.com”);

Scroll down to the desired location

   js.executeScript("window.scrollBy(0,2000)"); 

The window is not scrolled vertically by 2000 pixels

Q34) How to type a text in an input box using Selenium?

Ans: 

sendKeys() is the method used to type text in input boxes 

Consider the following example - 

  WebElement email = driver.findElement(By.id(“email”)); - Finds the “email” text using the ID locator

  email.sendKeys(“abcd.efg@gmail.com”);  - Enters text into the URL field

  WebElement password = driver.findElement(By.id(“Password”)); - Finds the “password” text using the ID locator

  password.sendKeys(“abcdef321”); - Enters text into the password field

Q35) Explain about the Page Object Model (POM)?

Ans: Each website page of the application has a relating page class that is answerable for finding the web components and performing activities. Page Object Model is a plan design that makes object storehouses for the web components. POM improves code readability and reusability. Various test cases can be run on the object repository.

Intermediate Level Selenium Interview Questions

Q36) How to retrieve CSS properties of an element in Selenium?

Ans: To retrieve CSS properties of an  element getCssValue() method is used in Selenium.

General Syntax:

  driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);

Example:

  driver.findElement(By.id(“youtube“)).getCssValue(“font”);

Q37) How to mouse hover over a web element?

Ans: 

Actions class utility is used to hover over a web element in Selenium WebDriver.

Instantiate Actions class.

    Actions action = new Actions(driver);

In this scenario, we hover over search box of a website

  actions.moveToElement(driver.findElement(By.id("id of the search box"))).perform();

Master important testing concepts such as Selenium WebDriver, Selenium IDE, TestNG, Selenium IDE, Selenium Grid. 

Q38) How does Selenium handle Windows-based pop-ups?

Ans: Selenium was intended to deal with web applications. Selenium does not locally uphold Windows-based highlights. Be that as it may, it can incorporate outsider instruments like AutoIT, Robot, and so on with Selenium to deal with pop-ups and different Windows-based highlights.

Q39) Can Captcha be automated in Selenium?

Ans: No, Selenium can't automate Captcha. Indeed, the entire idea of Captcha is to guarantee that bots and robotized programs don't get too touchy data - which is the reason, Selenium can't automate it. The automation test engineer needs to physically type the manual human test while it can fill different fields.

Q40) Is there any way to speed up the selenium server load time in Selenium Testing?

Ans: 

To have another duplicate of a Firefox cycle each time, however a touch pointless excess to twofold the startup time by recovering the Firefox profile. If you open a bug report on https://jira.openqa.org and email me at atrick@browsermob.com, I'll be glad to ensure we get an answer set up. 

PS: I've tackled this issue as a coincidental for myself. We utilize a similar Firefox profile and nuke out the reserve and treats DB. Yet, I definitely should fix that change back to the Selenium source. 

It's only a question of moving the code underneath outside of your test arrangement and into the apparatus arrangement and keeping worldwide of the selenium example (code accepts NUnit.)

[TestFixtureSetUp()]

 public void FixtureSetup()

{

selenium = New DefaultSelenium(“localhost”, 4444, “*firefox”, “https://1 ocalhost/”);

selenium.Start();

selenium.SetTimeout(“30000”);

selenium.Open(“/”);

}

Your test setup should then look something like this:

[Setup()]

public void SetUpTest()

{

selenium.Open(“default.aspx”);

selenium.WaitForPageToLoad(“30000”);

}

Q41) How to connect to the remote server in Selenium?

Ans: Ensure you have Selenium RC running. I utilize a simple bunch record considered Selenium.bat that resembles this: 

Java - container c:seleniumselenium-server.jar - multi-window (- multiwindow forestalls outline executioner code from breaking your test)

Q42) How to check URL for 404 using selenium webdriver?

Ans: Following code is used to check URL for 404 using Selenium webdriver: 

List allimages

= driver.findElements(By.tagName(“image”));

for (WebElement image : allimages) {

boolean loaded

= ((JavaScriptExecutor) driver).executeScript(

“return arguments[0].complete”, image);

if (!loaded) {

// Your error handling here.

}

}

You could use the getEval command to verify the value returned from the following JavaScript for each image on the page.

@TEST

public void checkForBrokenImages() {

selenium.open(“https://www.examples.comr);

int imageCount

= selenium.getXpathCount(“//img”).intValue();

for (int i = 0; i < imageCount; i++) {

String currentImage

= “this.browserbot.getUserWindow().document.images[” + i

+ “i”;

assertEquals(selenium.getEval(“(!” + currentImage

+ “.complete) ? false : !(typeof ” + currentImage

+ “.naturalWidth != rundefined” && ” + currentImage

+ “.naturalWidth == 0);”), “true”, “Broken image:

” + selenium.getEval(currentImage + “.src”));

}

}

Q43) No connection could be made because the target machine actively refused the selenium?

Ans: The objective machine effectively rejected it" signifies the server could be reached and reacted inside the break; however, the predefined port wasn't open. This can have a few reasons; for example, a neighbourhood firewall impeding the association. Is it true that you are sure the server is tuning in on the correct IP/port?

Q44) How to set a global base URL for every test case of one test suite in Selenium IDE?

Ans: On the off chance that you have a ton of experiments in a solitary suite, it's a torment to change the Base URL for each. All things being equal, make a different case for each Base URL you need to switch between. For instance, I have a store https:/testing. site. com/asmyEnvironment saved as experiment SetEnvTesting. I made another case for my creation site, SetEnvProduction. 

At that point, embed the ${myEnvironment} toward the start of every general URL in your experiments. For instance, open ${myEnvironment }/login . aspx. (This may be a torment if you have a lot of tests as of now. I recommend simply including it from now.) Then, just put the set-climate experiment toward the start of your test suite. To change your whole suite to another Base URL, just put an alternate set-climate case toward the beginning. Another decent thing is that you can switch conditions in the suite by placing an alternate set-climate case in the centre.

For instance: Example of using a SetEnvironment test case: 

SerEnvironment Testcase

The Current environment variable is utilized for each case in the suite. You can also make each different test suite utilize this equivalent SetEnvironment case, so they all switch together. That the Base Url gets unessential. You're superseding it. I trust that is useful! 

The experiment HTML record is answerable for setting the base URL. From the Selenium IDE, you can supersede the base URL for an experiment. A test suite, then again, is just a pack for your experiments. 

Eliminate the base URL setting from every one of the experiments records referred to from your test suite. At that point set the base URL by hand for the test suite and run the suite. 

On the off chance that it is missing, at that point, the base URL abrogates it consequently. 

Discovered it incredibly baffling that it couldn't simply have an exact Base URL and have it utilize whatever page I previously had open as the beginning of the test. What is the purpose of having the option to record relative URLs when it constrains you to hardcode a base URL that is prefixed to each overall previously had open as the beginning of the test? What is the purpose of having the option to record relative URLs when it drives you to hardcode a base URL that is prefixed to each relative URL (in this manner transforming them into supreme URLs)?? 

Stretching out on different answers and from this Q.: In Selenium IDE, how to get the estimation of the base URL 

SerEnvironment Testcase

You can store the current area in a variable and afterwards utilize that rather than a hardcoded one. This lets you log in to the worker you need to run the tests on, hit play And continue using the https://${host }/grammar for each relative URL you need in your content.

Advanced Level Selenium Interview Questions

Q45) The Best way to take screenshots of tests in Selenium2.0?

Ans: To take screenshots of tests in Selenium2.0 you need to do in the following way: 

driver = new FireFoxDriver(); // Should work in other Browser Drivers driver.Navigate().GoToUrl(“https://www.theautomatedtester.co.uk “);

Screenshot ss = ((ITakesScreenshot) driver).GetScreenshot();

//Use it as you want now string screenshot = ss.AsBase64EncodedString; byte[] screenshotAsByteArray = ss.AsByteArray; ss.SaveAsFile(“filename”, ImageFormat.Png); //use any of the built in image formating ss.ToString();//same as string screenshot =

ss.AsBase64EncodedString;

Code should work as I quickly tested it in IronPython Repl. See the IronPython code below import clr

clr.AddReference(“WebDriver.Common.d11”)

clr.AddReference(“WebDriver.Firefox.dll”)

from OpenQA.Selenium import *

from OpenQA.Selenium.Firefox import *

driver = FirefoxDriver()

driver.Navigate().GoToUrl(“https://www.theautomatedtester.co.uk “) s

= driver.GetScreenshot()

S = AsBaseEncodedString

# HUGE string appears in the REPL

I WebDriver driver = new InternetExplorerDriver(); driver.Navigate().GoToUrl(“https://www.google.com”);

Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();

ss.SaveAsFile(“ss.png”, System.Drawing.Imaging.ImageFormat.Pn );

by user800612 I don’t know if it matters, but I ended up having to cast the driver when i was writing in c#. something like:

Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();

Q46) Why webdriver and proxy server in Selenium?

Ans: Following code will help you to understand the webdriver and proxy server

You need to change “network.proxy.http” & “network.proxy.http_port” profile settings.

FirefoxProfile profile = new FirefoxProfile();

profile.addAdditionalPreference(“network.proxy.http”, “localhost”); profile.addAdditionalPreference(“network.proxy.http_port”, “31 28”);

WebDriver driver = new FirefoxDriver(profile);

Value for network . proxy . http_port should be integer (no quotes should be used) and network. proxy. type should be set as 1 (ProxyType . MANUAL, Manual proxy settings)

FirefoxProfile profile = new FirefoxProfile();

Webdriver driver = new firefox driver (profile);

The WebDriver API has been changed. The current snippet for setting the proxy is

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference(“network.proxy.http”, “localhost”);

profile.setPreference(“network.proxy.http_port”, “3128”);

WebDriver driver = new FirefoxDriver(profile);

For PAC based urls

Proxy proxy = new Proxy();

proxy.setProxyType(Proxy.ProxyType.PAC);

proxy.setProxyAutoconfigUrl(“https://some-server/staging.pac”);

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.PROXY, proxy);

return new FirefoxDriver(capabilities);

Just had fun with this issue for a couple of days and it was hard for me to find an for HTTPS, so here’s my take, for Java:

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference(“network.proxy.type”, 1);

profile.setPreference(“network.proxy.http”, “proxy.domain.exa mple.com”); profile.setPreference(“network.proxy.http_port”, 8080);

profile.setPreference(“network.proxy.ssl”, “proxy.domain.exam ple.com”); profile.setPreference(“network.proxy.sslport”, 8080); driver = new FirefoxDriver(profile);

Gotchas here: enter just the domain and not http: //proxy. domain . example. com, the property name is . ssl and not . https

Q47) Show how Capybara and cucumber click a non-link or button element?

Ans: With the following code you can click on an element in the Selenium: 

Element. click.

I add the following for this in my web_steps rb to click on divs.

When /A(?:II )click within “([“”]*)”$/ do ‘selector’ find(selector).click end

There is also an Element.trigger ( ‘ mouseover ‘ ) which appears to allow hover albeit not working with Selenium.

It is also very likely you will need to decorate your feature/scenario with . Capybaras provided @javascriptTag.

Q48) Take a screenshot with Selenium Webdriver?

Ans: Following code will give a glimpse how to take screenshot with Selenium webdriver:

WebDriver driver = new FirefoxDriver();

driver.get(“https://www.google.comr);

File scrFile

= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// Now you can do whatever you need to do with it, for example copy somewhere

FileLJtils.copyFile(scrFile, new File(“c: mpscrnshot.png” ));

in Python: #!/usr/bin/env python

from selenium import webdriver

browser = webdriver.Firefox()

browser.get(‘https://www.google.com/’) browser.save_screenshot(‘scrn.png’)

browser.quit()

by In ruby:

require ‘rubygems’

require ‘selenium-webdriver’

driver = Selenium::WebDriver.for :ie

driver.get “https://rAgw.google.com”

driver.save_screenshot(“iscrn.png”)

more file types and options are available and you can see them in takes_screenshot.rb

WebDriver augmentedDriver = new Augmenter().augment(driver); ((TakesScreenshot)augmentedDriver).getScreenshotAs(…); //works this way

In PHP (using PHPUnit_Selenium extension version 1.2.7):

Skip code block

class MyTestClass extends PHPUnit_Extensions_Selenium2TestCase

{

……..

public function screenshot($filepath) {

$filedata = $this->currentScreenshot();

file_put_contents($filepath, $filedata);

}

public function testSomething() {

$this->screenshot(‘/path/to/scrnshot.png’);

}

…..

}

Q49) How to check if an element is visible with the webdriver?

Ans: Following code will help you to check the element is visible with the webdriver: 

driver.findElements(By.tagName(“img1”));

for (WebElement image : alllmages) {

boolean loaded

= ((JavaScriptExecutor) driver).executeScript(

“return arguments[0].complete”, image1);

if (!loaded) {

// Your error handling here.

}

}

You could use the getEval command to verify the value returned from the following JavaScript for each image on the page.

@TEST

public void checkForBrokenImages() {

selenium.open(“https://www.example.comr);

int imageCount

= selenium.getXpathCount(“//img”).intValue();

for (int i = 0; i < imageCount; i++) {

String currentImage

= “this.browserbot.getUserWindow().document.images[” + i + “i”;

assertEquals(selenium.getEval(“(!” + currentImage

+ “.complete) ? false : !(typeof ” + currentImage

+ “.naturalWidth != rundefined” && ” + currentImage

+ “.naturalWidth == 0);”), “true”, “Broken image:

” + selenium.getEval(currentImage + “.src”));

}

}

Q50) Explain the relationship between Webdriver and Selenium RC?

Ans: You ought to most likely begin your exploration here (however you may have just gone over Selenium Org. 

I'll accept that you're differentiating Selenium-RC to WebDriver, Selenium-IDE truly isn't in a similar ballpark. Selenium utilizes JavaScript to computerize site pages. This allowed it to communicate firmly with web content and was one of the main robotization apparatuses to help Ajax and other unique pages. 

Anyway, this additionally implies : 

Selenium runs inside the JavaScript sandbox. This implies you need to run the Selenium-RC worker to get around the equivalent birthplace strategy, which can now and then reason issues with program arrangement. 

WebDriver, then again, utilizes local robotization from every language. While this implies it takes more time to help new programs/dialects, it offers a lot of nearer 'feel' to the program. In case you're content with WebDriver, stay with it, it's what's to come. 

There are constraints and bugs at present, yet if they're not halting you, take the plunge. 

Selenium Benefits over WebDriver: 

  • Supports numerous programs and numerous dialects, WebDriver needs local executions for each new dialect/program combo. 

  • Exceptionally develop and complete API 

  • Presently (Sept 2mo) underpins JavaScript alarms and affirms better. 

Advantages of WebDriver Compared to Selenium: 

  • Local computerization is quicker and somewhat less inclined to mistake and program design. 

  • Doesn't need Selenium-RC Server to be running 

  • Admittance to headless HTMLUnit can permit tests to run quick Great API 

Selenium WebDriver is the replacement of Selenium Remote Control which has been authoritatively censured. The Selenium Server (utilized by both WebDriver and Remote Control) presently additionally remembers worked for framework abilities.

For in-depth knowledge on Selenium, click on below