Time for action – working with OperaProfile - Selenium

Imagine that you want to test your web application that uses geolocation in the browser, when it cannot use geolocation. All location-based applications need to support this if you were to get a user who is worried about privacy on certain machines.

  1. Update the setUp() method to load the OperaDriver() : OperaProfile profile = new OperaProfile(); profile.preferences().set("Geolocation","Enable geolocation", false); driver = new OperaDriver(profile);
  2. Now we need to find an element. In this section we will find the link Chapter 4:

    WebElement element = driver.findElement(By.linkTexxt("Chapter 4"));
  3. Now we need to click on the link:

    element.click();
  4. Run your test and it should look like the following:

What just happened?

We have just seen how we can set a preference with Opera and then inject that into the browser so that when the browser starts, it is there for us to use. As mentioned earlier, there are a lot of different preferences that can be set. To see a list of these, open Opera and use the URL opera: config or visit http: //www.opera.com /support/ usingopera/ operaini/.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics