SELENIUM WEBDRIVER WITH PYTHON

From previous posts we talked about Selenium WebDriver with JAVA.

https://itmastermindblog.wordpress.com/2016/02/08/selenium-web-driver-with-java/

https://itmastermindblog.wordpress.com/2016/02/08/more-on-selenium-webdriver/

From this post I’m going to talk, how to use WebDriver with python. Let’s see how to install Selenium on linux to use with python.

  • There should be pip installed, in order to install Selenium.

100.png

  • Next we can install Selenium using the pip.

101.png

  • Now Selenium has installed successfully and we can import selenium in our python projects.
  • I’m going  to run the following code to check the Selenium on python.

104.png

It’s almost same the code what we used in JAVA.

First I import webdriver from the selenium module.

Then I have created a new Firefox object.

Then I’m redirecting to the Google site.

find_element_by_id() will return the element find out by it’s ID.

send_keys() will send the hello text to the browser.

get_attribute() will take the value back to the code.

Then using the print() method I have printed the output to the terminal.

Then the browser window will be closed using the close() method.

  • Let’s see the output.

105

106

All the methods are same in JAVA and python, only the syntax will be changed. Hope you got an idea about how to use python and Selenium WebDriver together. See you soon. Thank You!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s