How to click a href link from bootstrap tabs using Python?

When it comes to manipulation with web content, no one beats Python. A link can be clicked using Python and selenium library.

Installation

1.1 Selenium Bindings in Python
Selenium Python bindings provide a convenient API to access Selenium Web Driver like Firefox,Chrome,etc.

Pip install Selenium 

1.2 Web Drivers
Selenium requires a web driver to interface with the chosen browser. Web drivers is a package to interact with a web browser. It interacts with the web browser or a remote web server through a wire protocol which is common to all. You can check out and install the web drivers of your browser choice.

Chrome:    https://sites.google.com/a/chromium.org/chromedriver/downloads
Firefox: https://github.com/mozilla/geckodriver/releases
Safari:    https://webkit.org/blog/6900/webdriver-support-in-safari-10/

Note: You can check the source code of the website form here that bootstrap has been used to make the website. The website is CompCode  and You’ve to click the link References

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import the webdriver from selenium library
from selenium import webdriver
  
# Link the driver of the browser
driver = webdriver.Chrome("C://Myspace/chromedriver.exe")
  
# Open the website  using url
  
# Target the element using the href value
# In actual, search for an anchor tag and 
# among anchor tags, select the one with 
# given href value
target = driver.find_element_by_xpath('//a[@href="ref.html"]')
  
# Click the target to naviagate to destination
target.click()
  
  
# This Code has been contributed by Avanish Gupta

chevron_right


Output: 

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.