selenium webdriver (9) -- web控件

網頁中最多見的控件在selenium中是如何操做的html

輸入框 input boxpython

driver.find_element_by_id("XX").clear()
driver.find_element_by_id("XX").send_keys("XXX")

單選按鈕  radio boxweb

driver.find_element_by_id("radio").click()
element = driver.find_element_by_id("radio")
element.is_selected()

複選框 check box測試

driver.find_element_by_id("un-login").click()

連接    linkui

driver.find_element_by_link("網頁").click()

提交按鈕  submit buttoncode

driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("XXX")
driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys("XXX")
driver.find_element_by_name("password").submit()

下拉框    selecthtm

<select id="nr" name="NR">
    <option value="10">每頁顯示10條</option>
    <option value="10">每頁顯示20條</option>
    <option value="10">每頁顯示30條</option>
</select>

from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_name("NR"))
select.select_by_value("每頁顯示10條")

上面這些控件中只有下接框selenium有單獨的類提供element

deselect_all()
deselect_by_index(index)
deselect_by_value(value)
deselect_by_visible_text(text)
select_by_index(index)
select_by_value(value)
select_by_visible_text(text)
all_selected_options
first_selected_option

參考:input

《Selenium2自動化測試實戰》selenium

《selenium python buildings release 2》

相關文章
相關標籤/搜索