ウェブテストの自動化6つの-----セレクタ選択

図1は、一般的に、位置決め要素の最初の選択であります

selenium.webdriverインポートChromeから
selenium.webdriver.support.wait輸入WebDriverWaitからの
ことでselenium.webdriver.common.byインポートから
ECのようselenium.webdriver.supportから輸入expected_conditions 

ドライバ=クローム()

driver.get( 'のhttp:// www.baidu.com ')

setting_ele_xpath = '// [名@ = "tj_settingicon"とHREF @ = "http://www.baidu.com/gaoji/preferences.html"]' 

待つ= WebDriverWait(ドライバ、20 )
E = wait.until(EC.visibility_of_element_located((By.XPATH、setting_ele_xpath)))
driver.find_element_by_xpath(setting_ele_xpath).click()

ロケータ=(By.XPATH、「// [「、(テキストを()が含まれ高级搜索')] ")
(EC.element_to_be_clickable(ロケータ).until WebDriverWait(ドライバ、30))。(クリック)
クリック() 
#は、通常、位置決めオプションを行く、セレクタを探しに行きます
WebDriverWait待機=#(ドライバ、20がある)
#= my_selector wait.until(EC.element_to_be_clickable((By.NAME、 'フォート')))
#my_selector.click() 
ソースコードが出てロードされている、に直接行くことができますクリック
待ち= WebDriverWait(ドライバ、20)
my_option = wait.until(EC.element_to_be_clickable((By.XPATH、 '[値= "PPT" @]オプション//')))
my_option.clickを()

図2に示すように、セレクタのセレクタを使用して

selenium.webdriverインポートクロムから
selenium.webdriver.support.waitインポートWebDriverWaitから
選択selenium.webdriver.support.selectインポートから
によりselenium.webdriver.common.byインポートから
のECとしてselenium.webdriver.supportインポートexpected_conditionsから

ドライバ=クロム( )

driver.get( 'http://www.baidu.com')

DEF wait_clicl_element(ドライバ、ロケータ):
    待機= WebDriverWait(ドライバ、20)
    リターンwait.until(EC.element_to_be_clickable(ロケータ))

setting_ele_xpath =「// [名前@ = "tj_settingicon"とのhref = "http://www.baidu.com/gaoji/preferences.html" @]」

待つ= WebDriverWait(ドライバ、20) 
E = wait.until(EC.visibility_of_element_located(( By.XPATH、setting_ele_xpath)))
driver.find_element_by_xpath(setting_ele_xpath).click()
 
ロケータ=(By.XPATH、 "A // [含まれています(テキスト()、 '詳細検索')]")
(EC.element_to_be_clickable(ロケーター.until WebDriverWait(ドライバ、30) 。))をクリックします()

待機= WebDriverWait(ドライバ、20)がある
))my_selector = wait.until(EC.element_to_be_clickable((By.NAME 'フィート')
my_selector.click()

インデックス値:#選択する3つの方法を選択しますソースコードに、値の値、テキスト、ポイントを参照する
selector_objを=選択(my_selector)
selector_obj.select_by_value( 'PDF') キャンセルselector_obj.deselect_by_value()

印刷(selector_obj.options)
印刷(selector_obj.first_selected_option)

  

おすすめ

転載: www.cnblogs.com/qyh0902/p/11223216.html