DEV Community

Natesh M Bhat
Natesh M Bhat

Posted on

Automate your web pages with "webbot πŸ€–" without much code πŸš€πŸ”₯

What is webbot ?

webbot is a web automation library in Python. To be more descriptive , it a library used for web browser automation and to some extent can be used for ui automation and end to end testing. But why should you use this when clearly there are other alternatives πŸ˜„

Why you may want to use webbot ?

Here are some of the features that I have listed on my github page which I am directly quoting here :

  • Use any combination of selectors like id, name, text, css etc to perform actions on elements with one line of code.
  • Automate and test pages loaded dynamically by javascript.
  • Click any button or link without having to worry about finding the element first or knowing css_selectors , xpath etc
  • Smart scoring algorithm which finds the best matching elements on which you want to perform the action .
  • Automation designed to work even in case of webpages with dynamically changing id and classname
  • Immensely minimises the code required for performing input actions like clicks and keyboard actions.
  • Get webpage source , cookies , total tabs , webpage title etc..
  • Simulate key presses and special key combinations
  • Bidirectional scrolling
  • Perform an action on webpage elements by applying various filters to select the elements .
  • Perform action on multiple elements at once.
  • If certain elements don't have text or visible property , then use either their id , class , css_selector , xpath , tag etc.
  • The entire automation process can be made without having to open the browser window i.e in the background as a console process (see docs for more details)

Link to Code

GitHub logo nateshmbhat / webbot

Web automation library for simple and easy end to end testing and web browser automation that offers super charged features while keeping it simple to use and master

πŸ€– Crazy Smart Web automation and testing library for python

Downloads Downloads

webbot provides a much feature rich automation than selenium for all kinds of automation of webpage. Since the major portion of web automation is to perform actions like click and type into webpage elements , webbot automatically handles finding the right elements to perform the actions.

Buy me a coffee πŸ˜‡Buy me a coffee πŸ˜‡

Features :

  • Click any button or link without having to worry about finding the element first or knowing css_selectors , xpath etc
  • Automate and test pages loaded dynamically by javascript.
  • Smart scoring algorithm which finds the best matching elements on which you want to perform the action .
  • The entire automation process can be made without having to open the browser window i.e in the background as a console process (see docs for more details )
  • Use any combination of selectors like id, name, text, css etc to perform…

Here's a sample code snippet of webbot under action πŸ₯³

The below code will first go to google.com and search for the song "hello its me" and then come back to google and signs in with the provided email and password.

from webbot import Browser 
web = Browser()
web.go_to('google.com') 
web.type('hello its me')  # or web.press(web.Key.SHIFT + 'hello its me')
web.press(web.Key.ENTER)
web.go_back()
web.click('Sign in')
web.type('mymail@gmail.com' , into='Email')
web.click('NEXT' , tag='span')
web.type('mypassword' , into='Password' , id='passwordFieldId')
web.click('NEXT' , tag='span')

If you wish to use some lower level "find_element_by..." functions yourself , you are still covered 😁. Just get the underlying selenium driver object like this : web.driver

Why and How I made it ?

Well , honestly it was mostly about writing too much code when using selenium for web automation.

I was using selenium for some of my projects and it felt like I was writing way too much code than what was necessary. I realised that the reason this happened was not because of any inefficiency or bad api of selenium but it was just because of the way in which the interaction with the web was modelled upon.

What ? What do I mean by this ?

  • The web automation code first requires that the element is first found before we perform any action.
  • This means that we end up writing too much "find_element_by_..." code rather than focusing on just doing what we wanted : i.e just click that damn button which just said "click me".
  • So basically we first find the element which we were looking for and then perform the action. The action could be a click or a keyboard keypress , scroll etc
  • But what we as developers want is to just perform the action on some element not worry about finding it all by ourselves.
  • In a nut shell , what we want is an action centric approach rather than an element centric approach.

With webbot , that's the approach I am taking. An action centric approach rather than the usual element centric approach. You tell webbot what action you wanna do rather than trying to worry about all those css selectors , xpath , etc. Depending on the type of action you perform , whether it is click , type , keypress etc , it has a scoring algorithm that will find appropriate elements based on the action.

So for example , if you are trying to run web.click( 'sign in' ) , then it gives a scoring to all elements containing the 'sign in' text and the clickable elements (buttons , anchor tags , elements with onPress) etc take appropriate scores and the best scoring element from the lot is chosen to perform the click action.

Additional Thoughts / Feelings / Stories

I made this project during my college days. This is my graduation year. Loads and loads of memories to cherish. Now, when I look back , I realise that these were the best days of my life. These were the days where I lived more than I had ever ! Will miss all this so damn much. Anyway I am writing this article because I got an email from GitHub regarding a "graduation" ceremony for 2020 graduates. I am more than happy to take part in this :)

Thanks guys :)

You can check my other post on dev I wrote earlier here where I talk about using electron with react and typescript support :

Terminal Tweaker : An electron-react project to tweak the new windows terminal to heart's content ❀.

You can check me out on :
Github : https://github.com/nateshmbhat
LinkedIn : https://www.linkedin.com/in/nateshmbhat
Instagram : https://www.instagram.com/nateshmbhat
Facebook : https://www.facebook.com/profile.php?...
Twitter : https://twitter.com/nateshmbhat

Thank You for reading till this last line 😍 !!! You are amazing 😎!

Top comments (4)

Collapse
 
lizard profile image
Lizard • Edited

Opening new tabs doesn't work for me.

Edit: fixed it already. Added this code to the class in webbot.py

def new_tab(self, url):
        self.driver.execute_script(f"window.open('');") ;
        new_tab_position = self.get_total_tabs()
        self.switch_to_tab(new_tab_position)
        self.go_to(url)
Collapse
 
predentusl profile image
predentusl

Hello, it seems a promising module. Do you use only Google Chrome if showWindow isTrue? Selenium offers more choices geckodriver etc. Also the driverPath argument is not supported. Is your documentation correct? Thanx.

Collapse
 
gitakshat profile image
Akshat • Edited

It's really cool bro. I was looking for something like this. It's very helpful. Thanks. :)

Collapse
 
oueslati profile image
yath

Hello ,
I want to know if I can use webbot library to show me the xpath for an element.
I need help pls