webelement介面常用方法__web

來源:互聯網
上載者:User
from selenium import webdriverfrom time import sleep#webElement介面常用方法#clear():清除文字框中的內容#send_keys():類比鍵盤輸入#click():單擊按鈕,可以被點擊的元素;#可以是任何可以點擊的文字、圖片連結,單選框,複選框,下拉框#submit():提交表單,特別是沒有提交按鈕的情況#size:擷取元素尺寸#text:擷取元素文本#get_attribute(name):擷取屬性值driver=webdriver.Ie()driver.get("https://www.baidu.com")#百度輸入框中輸入testdriver.find_element_by_id('kw').send_keys("test")sleep(4)#清除testdriver.find_element_by_id('kw').clear()sleep(4)driver.find_element_by_id('kw').send_keys("python")#submit相當於斷行符號driver.find_element_by_id('kw').submit()sleep(4)#擷取百度搜尋方塊id的屬性值attribute=driver.find_element_by_id("kw").get_attribute("id")print("attibute:",attribute)#擷取百度輸入框的尺寸size=driver.find_element_by_id("kw").sizeprint("size:",size)#擷取百度首頁百度按鈕的文本資訊text=driver.find_element_by_id("su").textprint("百度按鈕的文本資訊是:",text)sleep(5)driver.quit()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.