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

Selenium Learning: simple element manipulation

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Common methods in WebDriver:

Clear () clears the text

Send_keys (* value) simulate keystroke input

Click () stand-alone element

The login of the website

From selenium import webdriverfrom time import * driver = webdriver.Chrome () url = "https://login.huawei.com/login/?redirect=http%3A%2F%2Fw3.huawei.com%2Fnext%2Findexa.html"print('new access% s'% (url) driver.get (url) driver.find_element_by_id ('uid'). Clear () driver.find_element_by_id (' uid'). Send_keys (" c00358145 ") sleep (3) driver.find_element_by _ id ('password'). Clear () driver.find_element_by_id (' password'). Send_keys (& CTT1106648034) driver.find_element_by_class_name ('btn'). Click () sleep (3) driver.quit () 2.WebElement interface commonly used method submit () method is used to submit forms from selenium import webdriverfrom time import * driver = webdriver.Chrome () url = "https://www.baidu.com"print('new access% s' % (url) driver.get (url) driver.find_element_by_id ('kw'). Clear () driver.find_element_by_id (' kw'). Send_keys ("c00358145") sleep (3) driver.find_element_by_id ('kw'). Submit () sleep (3) driver.quit ()

The location search box submits the contents of the search box through submit to achieve the effect of clicking the search button, and sometimes it can be exchanged with the click () function.

Method: size () returns the size of the element

Text () gets the text of the element

Get_attribute (name) gets the value of the attribute

Is_displayed () sets the down payment for this element to be visible to the user

From selenium import webdriver

From time import *

Driver = webdriver.Chrome ()

Url = "https://www.baidu.com"

Print ('new access% s'% (url))

Driver.get (url)

Size = driver.find_element_by_id ('kw'). Size

Print ('size%s' size)

Text = driver.find_element_by_xpath ("/ / * [@ id='u1'] / a [1]") .text

Print ('text%s' text)

Attribute = driver.find_element_by_id ('kw'). Get_attribute (' type')

Print ('% s'% attribute)

Sleep (3)

Driver.quit ()

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

Internet Technology

Wechat

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

12
Report