Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the drop-down box with python+selenium

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use python+selenium to achieve drop-down box" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "how to use python+selenium drop-down box" article can help you solve the problem.

Basic scaffolding code:

From selenium.webdriver.support.ui import Selectfrom selenium import webdriverimport timedriver = webdriver.Chrome () driver.get ('https://www.17sucai.com/pins/demo-show?id=5926')# switches to iframedriver.switch_to.frame (driver.find_element_by_id (' iframe')

Locate the drop-down box (take the first drop-down box as an example)

Select () method

Select_elm = Select (driver.find_element_by_class_name ('nojs'))

This positioning is not recommended:

Select_elm = driver.find_element_by_class_name ('nojs'). Click ()

Check the drop-down box and click:

Driver.find_element_by_xpath ('/ / option [@ value= "JP"]') .click ()

The optional values for the first drop-down box are shown in the figure:

There are three ways to select a value in the drop-down box

1. Select according to the index

Select_elm.select_by_index (2)

In accordance with the index rules, count from 0, and the Canada value is automatically selected.

two。 Select according to valu

Select_elm.select_by_value ('CA')

The value here refers to the value attribute, not the text string.

The running result is the same as above.

3. Select based on visual text

Select_elm.select_by_visible_text ('Canada')

That is, what you see is what you choose.

The running result is the same as above.

This is the end of the introduction of "how to use python+selenium to achieve the drop-down box". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report