Selenium之編輯框操做

編輯框操做:html

      網頁上隨處可見的編輯框,有時候編輯框裏有默認的提示文字或者當咱們須要輸入第二次測試數據時,須先用clear()方法清除該元素裏的字符串,再輸入文本;web

 那麼如何獲取輸入框已經輸入的文本內容呢?如能夠用input1.get_attribute('value')。chrome

下面附上edit1.html的代碼截圖:less

        

經過selenium實現編輯框操做:測試

import timeui

from selenium import webdriverhtm

# 指定驅動blog

driver = webdriver.Chrome(r"C:\webdriver\chromedriver.exe")element

# 打開網址字符串

driver.get('file:///C:/Users\Administrator/PycharmProjects/1120/web_driver/lesson3/edit1.html')

# 元素定位到編輯框

input1 = driver.find_element_by_id('input1')

# 清除原來輸入框的字符

input1.clear()

# 再輸入文本內容

input1.send_keys('Selenium')

# 獲取輸入框已經輸入的文本內容

# print(input1.get_attribute('value'))

time.sleep(2)

driver.quit()

相關文章
相關標籤/搜索