In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to achieve the selenium_webdriver drop-down box in Python. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Environment building
First of all, build the basic environment based on python3.x.
1. Install the python base environment (python's base environment is too simple to talk about here)
two。 After installing python, we need to install python's basic toolkit pip. Normally, when you install python, you install the pip basic package, but there are some people who don't install it.
i. Download the pip installation package, remember what exe file you are looking for here, and install it directly with the source code.
ii. Extract pip-9.0.1.tar.gz and execute python setup.py to install pip
After the 3.pip installation is complete, open the command line as an administrator to execute the pip install selenium installation selenium. (setting up the environment is that simple.)
4. Install webdriver driver, driver download requires FQ, since you want to learn automation, FQ must be very easy, I use the chrome browser here, so download the chromedriver driver.
IEdriver download address: http://selenium-release.storage.googleapis.com/index.html
Note: due to the different version of the browser, please choose the driver version according to your own situation. If the version does not match, you will be prompted to report an error when you open the browser. When you see the following picture, your version is no longer compatible.
The version of the Chrome installed here is 58.0.3029.81 and the version of the chromedriver is 2.29.
5. Remember that the webdriver driver should be stored in the python installation directory, that is, at the same level as python.exe, otherwise you will not be able to open the browser.
Python selenium_webdriver drop-down box operation
The drop-down box operation needs to use: from selenium.webdriver.support.select import Select to introduce the Select class:
From selenium import webdriver # introduce webdriverfrom selenium.webdriver.support.select import Select # introduce Selectfrom time import sleep # introduce time driver = webdriver.Firefox () # Open Firefox driver.get ('file:///C:/Users/CY-MHQ/Desktop/%E6%B1%87%E6%99%BA%E5%8A%A8%E5%8A%9B/%E8%87%AA%E5%8A%A8%E5%8C%96/4select%20 -% 20% E4% B8% 8B% E6% 8B% 89% E6% A1% 86.html') # enter the web page select_ele = driver.find_element ('id' 'nr') # navigate to the drop-down box where id is nr and name it select_eleselect_ob = Select (select_ele) # generate the drop-down box instance object select_ob.select_by_index (2) # Select the third drop-down box
The methods in the class are:
Select_by_index ('index') # through index selection, the index starts at 0
Select_by_value ('value') # selected by the value of value
Select_by_visible_text ('text') # through text selection
Options # returns all selections
Is_multiple # determines whether it is multiple values. If so, it returns True, otherwise returns None.
First_selected_option # returns the first selected option
Deselect_by_visible_text ('text') # deselect by text
Deselect_by_value ('value') # deselect by value
Deselect_by_index ('index') # deselect by index
All_selected_options # returns all selected selections
Deselect_all () # deselect all
This is the end of the article on "how to achieve the selenium_webdriver drop-down box in Python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.