search
HomeBackend DevelopmentPython TutorialHow to click href link from Bootstrap tab using Python?
How to click href link from Bootstrap tab using Python?Sep 01, 2023 pm 04:21 PM
pythonbootstraphref

Bootstrap is a popular HTML, CSS, JavaScript framework that helps us develop responsive, mobile-first front-end web applications. It provides design templates for forms, typography, navigation, buttons and other interface components. Python is the best language for manipulating web content.

Selenium Library

If we need to click a link using Python programming, we should use selenium library. It is the most popular open source automated testing tool that allows us to automate web browsers.

Selenium is primarily used for automating testing purposes of web applications, but is also used for other purposes such as automating repetitive tasks and web scraping. It supports programming languages ​​such as Python, Java, C, and Ruby. Can be used to test Google, Mozilla Fire Fox, safari and other web browsers.

Steps to follow

Here are the steps to automatically open a given href link from bootstrap tab using selenium.

  • Install the selenium library: First, we need to install the selenium library in the python environment. The following is cod

pip install Selenium

If the installation is successful, we will get the following output -

Collecting Selenium
  Downloading selenium-4.8.3-py3-none-any.whl (6.5 MB)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing collected packages: outcome, h11, exceptiongroup, async-generator, wsproto, trio, trio-websocket, Selenium
Successfully installed Selenium-4.8.3 async-generator-1.10 exceptiongroup-1.1.1 h11-0.14.0 outcome-1.2.0 trio-0.22.0 trio-websocket-0.10.2 wsproto-1.2.0
Note: you may need to restart the kernel to use updated packages.
  • Import Web Driver - selenium package for automating web browser interactions in Python. Supports multiple browsers/drivers (Firefox, Chrome, Internet Explorer) and remote protocols.

Import the webdriver package from the Selenium library.

from selenium import webdriver
  • In this step, we link the website’s driver with the webdriver package

web_driver = webdriver.Chrome("D://Myspace/chromedriver.exe")
  • Next, we will open the href link using the get() function of the webdriver package by assigning the website link.

web_driver.get("https://www.Tutorialspoint.com/")

Let’s combine all the above steps together and see the output.

from selenium import webdriver
web_driver = webdriver.Chrome("D://Myspace/chromedriver.exe")
web_driver.get("https://www.Tutorialspoint.com/")
print("The website link opened")

Output

The following is the output of the above code. When we run the program, the specified link will be opened.

How to click href link from Bootstrap tab using Python?

Example

Here is another example of clicking an href link from the bootstrap tab using python.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "https://Tutorialspoint.com"
driver_path = "path/to/webdriver"
driver = webdriver.Chrome(driver_path)
driver.get(url)
tab_link = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, 'a[data-toggle="tab"][href="#tab-1"]'))
)
tab_link.click()
WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, "tab-1"))
)
link_url = driver.current_url
driver.get(link_url)
print(driver.page_source)
driver.quit()

Output

The output of the above code is as follows.

How to click href link from Bootstrap tab using Python?

The above is the detailed content of How to click href link from Bootstrap tab using Python?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete
10款好看又实用的Bootstrap后台管理系统模板(快来下载)10款好看又实用的Bootstrap后台管理系统模板(快来下载)Aug 06, 2021 pm 01:55 PM

一个好的网站,不能只看外表,网站后台同样很重要。本篇文章给大家分享10款好看又实用的Bootstrap后台管理系统模板,可以帮助大家快速建立强大有美观的网站后台,欢迎下载使用!如果想要获取更多后端模板,请关注php中文网后端模板栏目!

bootstrap与jquery是什么关系bootstrap与jquery是什么关系Aug 01, 2022 pm 06:02 PM

bootstrap与jquery的关系是:bootstrap是基于jquery结合了其他技术的前端框架。bootstrap用于快速开发Web应用程序和网站,jquery是一个兼容多浏览器的javascript库,bootstrap是基于HTML、CSS、JAVASCRIPT的。

7款实用响应式Bootstrap电商源码模板(快来下载)7款实用响应式Bootstrap电商源码模板(快来下载)Aug 31, 2021 pm 02:13 PM

好看又实用的Bootstrap电商源码模板可以提高建站效率,下面本文给大家分享7款实用响应式Bootstrap电商源码,均可免费下载,欢迎大家使用!更多电商源码模板,请关注php中文网电商源码​栏目!

8款Bootstrap企业公司网站模板(源码免费下载)8款Bootstrap企业公司网站模板(源码免费下载)Aug 24, 2021 pm 04:35 PM

好看又实用的企业公司网站模板可以提高您的建站效率,下面PHP中文网为大家分享8款Bootstrap企业公司网站模板,均可免费下载,欢迎大家使用!更多企业站源码模板,请关注php中文网企业站源码栏目!

bootstrap中sm是什么意思bootstrap中sm是什么意思May 06, 2022 pm 06:35 PM

在bootstrap中,sm是“小”的意思,是small的缩写;sm常用于表示栅格类“.col-sm-*”,是小屏幕设备类的意思,表示显示大小大于等于768px并且小于992px的屏幕设备,类似平板设备。

bootstrap默认字体大小是多少bootstrap默认字体大小是多少Aug 22, 2022 pm 04:34 PM

bootstrap默认字体大小是“14px”;Bootstrap是一个基于HTML、CSS、JavaScript的开源框架,用于快速构建基于PC端和移动端设备的响应式web页面,并且默认的行高为“20px”,p元素行高为“10px”。

bootstrap modal 如何关闭bootstrap modal 如何关闭Dec 07, 2020 am 09:41 AM

bootstrap modal关闭的方法:1、连接好bootstrap的插件;2、给按钮绑定模态框事件;3、通过“ $('#myModal').modal('hide');”方法手动关闭模态框即可。

bootstrap是免费的吗bootstrap是免费的吗Jun 21, 2022 pm 05:31 PM

bootstrap是免费的;bootstrap是美国Twitter公司的设计师“Mark Otto”和“Jacob Thornton”合作基于HTML、CSS、JavaScript 开发的简洁、直观、强悍的前端开发框架,开发完成后在2011年8月就在GitHub上发布了,并且开源免费。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.