Selenium learning: simple element manipulation

Source: Internet
Author: User

Common methods in Webdriver:

Clear () Erase text

Send_keys (*value) analog key input

Click () stand-alone element

    1. Landing 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 Common methods The Submit () method is used to submit the form 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 ()

Locate the search box by submitting the content of the search box to reach the Click search button effect, and sometimes can be used with the click () function Exchange

Method: Size () returns the dimension of the element

Text () Gets the literal of the element

Get_attribute (name) Gets the value of the property

Is_displayed () Set the element down payment user visible

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 ()


Selenium Learning: simple element manipulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.