Installation

Required Dependencies

[ ]:
!pip install selenium
!pip install webdriver-manager

installing the browser_automationpy

[ ]:
!python3 -m pip install browser_automationpy

Browser setup

[ ]:
import browser_automation

Custom Options : Optional

google colab Jupyter notebook Instruction :
Ctrl m m will convert a code cell to a text cell.
Ctrl m y will convert a text cell to a code cell.

If require browser with custom options, Please use below given code cell to output sample custom options templates.

[ ]:
# Outputs the json template files
browser_automation.browser_setup.CustomOptions().get_default_custom_options_json()

Edit the template based on your need and provide the file path in cell below. if filename and location is not changed no need to change anything.

[ ]:
custom_browser_option_json_path = './customoption.json'

Launch Browser

if you are using custom options put ‘custom_browser_option_json_path’ inside Interactions(here in below cell)

[ ]:
temp_browser = browser_automation.browser_manipulation.Interactions()


====== WebDriver manager ======
Current google-chrome version is 84.0.4147
Get LATEST driver version for 84.0.4147
Driver [/home/chaudharyubuntu/.wdm/drivers/chromedriver/linux64/84.0.4147.30/chromedriver] found in cache
[ ]:
driver = temp_browser.driver

Now you can use selenium driver methods with extra methods provided in this package

How to start with browser automation

[ ]:
# opening a website
website_link = "https://selenium.dev"
driver.get(website_link)

To interact with web elements like buttons and input boxes, addresses are required. check selenium guide or extensions like- selectorshub, selocity, Chropath for locating web elements and get addresses. It’s way easier than it might seem.

element_locator_type : str
these by selenium methods to locate web element. This function contains CLASS_NAME, CSS_SELECTOR, ID, LINK_TEXT, NAME, PARTIAL_LINK_TEXT, TAG_NAME, XPATH.
[ ]:
# clicking on buttons
address_of_xpath_type = "//a[@class='nav-link']//span[contains(text(),'Documentation')]"
element_locator_type = "xpath"
driver.click_on_button(element_locator_type, address_of_xpath_type)
[ ]:
# putting text in input boxes
address_of_xpath_type = "//input[@role='combobox']"
element_locator_type = "xpath"
driver.write_in_inputbox("xpath", mdpi_search_inputbox_xpath, "text to put in the box")
[ ]:
# scrolling the webpage
#scroll_until : int This is the total amount of scrolling.
#scroll_height : int This is how much scroll is happen in one go
scroll_until = 400
scroll_height = 300
driver.scroll_page(scroll_until, scroll_height)
[ ]:
#code for sleeping for random time to minimise load on server.
browser_automation.os_json_utils.RandomSleep().sleep_for_random_time()
[ ]:
# renaming and moving files
browser_automation.DownloadUtil().file_rename_and_moving('article_name', "DOWNLOAD_LOCATION_path", "new_path")

For leaning more about browser automation check out https://www.selenium.dev/documentation/