Selenium – Open Safari browser

Python Selenium – Open Safari

In this tutorial, you shall learn how to open Safari browser, using Selenium, in Python language.

Prerequisites

We have to set the Allow Remote Automation to open Safari browser using Selenium.

To set Allow Remote Automation in Safari browser,

  • Open Safari browser.
  • Click on Develop menu.
  • Make sure the menu item Allow Remote Automation is checked. If not checked already, click on it.
Python Selenium - Open Safari

Steps to open Safari browser using Selenium Python

Step 1

Import webdriver module from selenium module.

from selenium import webdriver

Step 2

Create a Safari driver instance using webdriver.Safari() class.

driver = webdriver.Safari()

Example

In the following example, we followed the above said steps to create a Safari driver instance, and open a Safari browser window.

Python Program

from selenium import webdriver

# Setup Safari driver
driver = webdriver.Safari()

# Navigate to the url
driver.get('https://pythonexamples.org/tmp/selenium/index.html')

# Close the driver
driver.quit()
Copy

Screenshot

Python Selenium - Open Safari

Summary

In this Python Selenium Tutorial, we have seen how to create a Safari driver instance and open a Safari browser window.

Quiz on Selenium

Q1. What is the method used to navigate back to the previous page in Selenium Python?

Not answered

Q2. Which of the following is not a commonly used assertion method in Selenium Python?

Not answered

Q3. What is the method used to switch to a different frame in Selenium Python?

Not answered

Q4. What is the method used to take a screenshot in Selenium Python?

Not answered

Q5. What is the method used to clear the text from an input field in Selenium Python?

Not answered
Code copied to clipboard successfully 👍