banner



How To Make A Web Browser In Python

Guest Contributor · 8 min read · Updated oct 2020 · Spider web Scraping · Sponsored

As of September 2020, Microsoft Edge holds 8.84% of the browser marketand stands at the second position after Chrome. But still, while performing Cantankerous Browser Testing, our main focus tends to revolve around browsers like Chrome, Firefox, or Safari primarily. But what about other browsers, like Edge?

While testing a website, it is quite important that it is rendered smoothly and accurately over all browsers, devices, and machines. Suppose you created a website and tested it on browsers similar Chrome, Firefox, and Safari manually, and decided to deploy it. Just what if the users open up the website in Microsoft Edge, or in a version of browsers other than the tested ones ?

Therefore information technology is quite of import to perform Automated Browser Testing, to examination your website beyond multiple browser-version combinations, and then every bit to ensure efficient user feel, with the help of Selenium. In this tutorial, we will dive in-depth on how to perform automated browser testing with Edge and Selenium in Python. Nosotros will be using the Edge WebDriver to help u.s.a. run our Selenium automation test scripts over the Border browser.

Download Selenium Edge WebDriver

While performing automatic browser testing, information technology is of import for the test scripts to communicate with the browser. Without having a WebDriver, this might not be possible. The Selenium Border WebDriver works every bit the mediator between your lawmaking and the browser, which helps to provide the programmable remote command of the browser.

Yous tin download the latest version of Selenium Border WebDriver using this link.

Performing Browser Automation With Edge And Selenium In Python

Permit united states of america come across what are the prerequisites to use Edge with Selenium and Python for browser automation:

  • Download the latest version of Python, if non already installed, from hither.
  • Adjacent, we need the Microsoft Edge browser. You can use this link to download information technology. Please note the version that you are downloading, for WebDriver purpose. If you have Edge already installed, you can find out its version by typing the beneath command in Edge's address bar:
    • edge://version/
  • Yous tin also discover out the version of your Edge browser, using the below steps:
    • Open the Microsoft Edge browser.
    • Select Settings and more than at the height right of the browser and become to Settings.
    • You can see a section About Microsoft Edge at the lesser of the settings tab, that contains the information virtually your Edge's version.

Now that the basic setup is ready, let'southward proceed to the next steps to download and install the following:

  • Selenium framework for Python – Execute the below control in the concluding, after you have already installed Python linguistic communication, to install the latest version of Selenium framework for Python language:
          pip3 install selenium        
  • Border WebDriver for Selenium – Download the Border WebDriver executable from this link that matches your organization'due south configuration. Make sure to download the version of the driver based on the version of Edge installed in your system. Unzip the file and copy the location of the msedgedriver.exe.
  • Selenium tools for Microsoft Edge – Execute the below command from the last to download the Selenium tools for Microsoft Edge directly:
          pip install msedge-selenium-tools selenium==3.141        

Nosotros are all fix. Now we can perform automation testing with Edge and Selenium in Python. Let the states see some examples.

Running Your First Automated Browser Testing Script

In this example, we will see how to write the first script that initiates the automated browser testing with Edge and Selenium:

          # importing required bundle of webdriver from selenium import webdriver # Just Run this to execute the below script if __name__ == '__main__':    # Instantiate the webdriver with the executable location of MS Edge web driver    browser = webdriver.Border(r"C:\Users\LenovoE14\Downloads\edgedriver\msedgedriver.exe")    # But just open a new Border browser and become to lambdatest.com    browser.get('https://world wide web.lambdatest.com')        

In this code higher up, we are just creating the WebDriver example for Microsoft Edge, by passing the path of the executable Edge WebDriver as parameter. In this case, it is C:\Users\LenovoE14\Downloads\edgedriver\msedgedriver.exe. So we are opening a new Edge instance with a provided URL. Yous can customize the URL as per your choice.

Execute the above code and yous will encounter an example of the Microsoft Edge getting started with 'https://www.lambdatest.com' in its accost bar (because we have provided this accost to the webdriver instance and asked the browser to open up information technology):

First script executed

Performing Browser Automation Using Spider web Locators

Let us now look at another example, to perform some specific actions, with the help of spider web locators. In this example, nosotros volition attempt to insert the email address at the home page of www.lambdatest.comand click on the button Start Gratuitous Testing, as shown in the beneath prototype:

Start free testingCopy and paste the beneath code in your IDE/Text editor and run information technology:

          # importing required package of webdriver from selenium import webdriver from selenium.webdriver.chrome.options import Options from time import sleep from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException from selenium.webdriver.back up.ui import WebDriverWait from selenium.webdriver.opera.options import Options from selenium.webdriver.support.expect import WebDriverWait  if __name__ == '__main__':     # Instantiate the webdriver with the executable location of MS Border     browser = webdriver.Edge(r"C:\Users\LenovoE14\Downloads\edgedriver\msedgedriver.exe")     # Only only open a new Border browser and become to lambdatest.com     browser.maximize_window()     browser.go('https://www.lambdatest.com')     try:         # Get the text box to insert Email using selector ID         myElem_1 = WebDriverWait(browser, x).until(EC.presence_of_element_located((By.ID, 'useremail')))         # Entering the email address         myElem_1.send_keys("[email protected]")         myElem_1.click()         # Go the Submit button to click and start gratuitous testing using selector CSS_SELECTOR         myElem_2 = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#testing_form > div")))         # Starting free testing on LambdaTest         myElem_2.click()         sleep(10)     except TimeoutException:         print("No element institute")     sleep(x)     browser.shut()        

In the code above, we have inserted the e-mail address in the text box shown above and pressed the button Start Free Testing. Nosotros have used the selectors ID and CSS SELECTOR for this. Upon execution, a new instance of Microsoft Border will open and perform the post-obit actions in the given order:

New case of Microsoft Edge will be launched:

Microsoft Edge instance launched using Selenium The browser volition become maximized (equally we execute the browser.maximize_window()):

Browser Maximized

The LambdaText homepage will open:

Home page opened

Given email will be inserted in the text box and the button Commencement Free Testing volition be pressed:

Email inserted

You'll exist redirected to the login page to set up your account and first your cross browser testing with the help of LambdaText:

Redirected to Login Page Decision

In this article, we have successfully seen:

  • What is Edge WebDriver and how to get it.
  • How to ready automated browser testing with Edge and Selenium in Python.
  • Writing the first browser automated test.
  • Using Selectors to perform browser automation with Border and Selenium in Python.

The popularity of Microsoft Border is constantly rising. We have performed the browser automation using an installed version. But what if we need to perform this in some other version, or some other Windows Os version ?

In such a scenario, downloading and testing each version might not be possible, thereby leading to sure drawbacks or some user experience issues later. To overcome this, nosotros can use LambdaTest for cross browser testing. LambdaTest will not but allow you to test your website on multiple browsers and operating system combinations, but will allow you lot to perform parallel testing as well on cloud Selenium Filigree.

LambdaTest provides a platform to perform alive interactive browser compatibility testing of your public or locally hosted websites and web apps on 2000+ real mobile and desktop browsers running on real operating systems.

Learn also: How to Apply Proxies to Rotate IP Addresses in Python.

Happy testing ♥

View Full Code


Read Also


How to Use Proxies to Rotate IP Addresses in Python

How to Extract Script and CSS Files from Web Pages in Python

How to Extract All Website Links in Python


Comment panel

Source: https://www.thepythoncode.com/article/automated-browser-testing-with-edge-and-selenium-in-python

Posted by: shercarly1965.blogspot.com

0 Response to "How To Make A Web Browser In Python"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel