最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python-web根據(jù)元素屬性進(jìn)行定位的方法

 更新時(shí)間:2019年12月13日 09:22:57   作者:MeriaChen  
這篇文章主要介紹了python-web根據(jù)元素屬性進(jìn)行定位的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1. 根據(jù)屬性ID值進(jìn)行定位

def test_find_element_by_id(self):
  # 定位搜索文本框
  search_input = self.driver.find_element_by_id("kw")
  # 輸入關(guān)鍵字
  search_input.send_keys("馬云")
  # 定位搜索按鈕
  search_button = self.driver.find_element_by_id("su")
  # 點(diǎn)擊搜索按鈕
  search_button.click()
  # 喘口氣
  time.sleep(2)
  # 斷言結(jié)果
  actual_result = self.driver.page_source
  expect_result = "馬云"
  self.assertIn(expect_result, actual_result)

2. 根據(jù)屬性CLASS值進(jìn)行定位

def test_find_element_by_class_name(self):
  # 定位搜索文本框
  search_input = self.driver.find_element_by_class_name("s_ipt")
  # 輸入關(guān)鍵字
  search_input.send_keys("奧巴馬")
  # 定位搜索按鈕
  search_button = self.driver.find_element_by_id("su")
  # 點(diǎn)擊搜索按鈕
  search_button.click()
  # 喘口氣
  time.sleep(2)
  # 斷言結(jié)果
  actual_result = self.driver.page_source
  expect_result = "奧巴馬"
  self.assertIn(expect_result, actual_result)

3. 根據(jù)屬性NAME值進(jìn)行定位

def test_find_element_by_name(self):
  # 定位搜索文本框
  search_input = self.driver.find_element_by_name("wd")
  # 輸入關(guān)鍵字
  search_input.send_keys("特朗普")
  # 定位搜索按鈕
  search_button = self.driver.find_element_by_id("su")
  # 點(diǎn)擊搜索按鈕
  search_button.click()
  # 喘口氣
  time.sleep(2)
  # 斷言結(jié)果
  actual_result = self.driver.page_source
  expect_result = "特朗普"
  self.assertIn(expect_result, actual_result)

4. 根據(jù)標(biāo)簽名稱進(jìn)行定位

5. 根據(jù)鏈接全部內(nèi)容進(jìn)行定位

6. 根據(jù)鏈接部分內(nèi)容進(jìn)行定位

def test_find_element_by_tag_name(self):
  # 定位搜索文本框
  search_input = self.driver.find_element_by_class_name("s_ipt")
  # 輸入關(guān)鍵字
  search_input.send_keys("馬化騰")
  # 定位搜索按鈕
  search_button = self.driver.find_element_by_id("su")
  # 點(diǎn)擊搜索按鈕
  search_button.click()
  # 喘口氣
  time.sleep(2)
  # 獲取頁面的返回結(jié)果
  # tag_names = self.driver.find_elements_by_tag_name("h3")
  # for tag_name in tag_names:
  #   print(tag_name.text)
  #   # 通過鏈接的文本信息進(jìn)行定位
  #   link_text = self.driver.find_element_by_link_text(tag_name.text)
  #   # 對百度的結(jié)果依次進(jìn)行點(diǎn)擊
  #   link_text.click()
  # 根據(jù)部分鏈接文字進(jìn)行定位
  pony_infos = self.driver.find_elements_by_partial_link_text("馬化騰")
  for pony_info in pony_infos:
    # 依次打印每個(gè)元素的文本信息
    print(pony_info.text)
  # 斷言結(jié)果
  actual_result = self.driver.page_source
  expect_result = "馬化騰"
  self.assertIn(expect_result, actual_result)

7. 根據(jù)xpath進(jìn)行定位

def test_find_element_by_xpath(self):
  # 找到搜索輸入框
  # search_input = self.driver.find_element_by_xpath('/html/body/div[@id="wrapper"]/div[@id="head"]/div[@class="head_wrapper"]/div[@class="s_form"]/div[@class="s_form_wrapper soutu-env-nomac soutu-env-index"]/form[@class="fm"][@id="form"]/span[@class="bg s_ipt_wr quickdelete-wrap"]/input[@id="kw"][@class="a_ipt"]')
  search_input = self.driver.find_element_by_xpath('//*[@id="kw"]')
  # 輸入關(guān)鍵字
  search_input.send_keys("天黑請閉眼")
  # 找到搜索按鈕
  # search_button = self.driver.find_element_by_xpath('/html/body/div[@id="wrapper"]/div[@id="head"]/div[@class="head_wrapper"]/div[@class="s_form"]/div[@class="s_form_wrapper soutu-env-nomac soutu-env-index"]/form[@class="fm"][@id="form"]/span[@class="bg s_btn_wr"/input[@id="su"][@class="bg s_btn"]')
  search_button = self.driver.find_element_by_xpath('//*[@id="su"]')
  # 點(diǎn)擊搜素按鈕
  search_button.click()
  # 喘口氣
  time.sleep(1)
  # 斷言結(jié)果
  expect_value = "天黑請閉眼"
  actual_value = self.driver.page_source
  self.assertIn(expect_value,actual_value)

8. 根據(jù)css選擇器進(jìn)行定位

def test_find_element_by_css_selector(self):
  # search_input = self.driver.find_element_by_css_selector("#kw")
  search_input = self.driver.find_element_by_css_selector("input#kw")
  search_input.send_keys("狼人殺")
  search_button = self.driver.find_element_by_css_selector("input.bg.s_btn")
  search_button.click()
  # 喘口氣
  time.sleep(1)
  # 斷言結(jié)果
  expect_value = "狼人殺"
  actual_value = self.driver.page_source
  self.assertIn(expect_value, actual_value)

總結(jié)

以上所述是小編給大家介紹的python-web根據(jù)元素屬性進(jìn)行定位的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • Python采用Django開發(fā)自己的博客系統(tǒng)

    Python采用Django開發(fā)自己的博客系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Python采用Django開發(fā)自己的博客系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • python for和else語句趣談

    python for和else語句趣談

    這篇文章主要介紹了python for和else語句趣談,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Python 可迭代對象 iterable的具體使用

    Python 可迭代對象 iterable的具體使用

    本文主要介紹了Python可迭代對象iterable,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Python?selenium模塊的安裝和配置教程

    Python?selenium模塊的安裝和配置教程

    這篇文章主要為大家介紹了python中selenium模塊的安裝和配置環(huán)境變量教程、提取數(shù)據(jù)操作、無頭模式,有需要的朋友可以借鑒參考下,希望能夠?qū)Υ蠹矣兴鶐椭?/div> 2022-10-10
  • PyTorch中topk函數(shù)的用法詳解

    PyTorch中topk函數(shù)的用法詳解

    今天小編就為大家分享一篇PyTorch中topk函數(shù)的用法詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • Python+OpenCV圖像處理之直方圖統(tǒng)計(jì)

    Python+OpenCV圖像處理之直方圖統(tǒng)計(jì)

    直方圖就是對圖像的另外一種解釋,它描述了整幅圖像的灰度分布。通過直方圖我們可以對圖像的亮度、灰度分布、對比度等有了一個(gè)直觀的認(rèn)識(shí)。本文將為大家詳細(xì)介紹一下如何通過OpenCV實(shí)現(xiàn)直方圖統(tǒng)計(jì),感興趣的可以了解一下
    2021-12-12
  • django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式

    django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式

    這篇文章主要介紹了django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • keras導(dǎo)入weights方式

    keras導(dǎo)入weights方式

    這篇文章主要介紹了keras導(dǎo)入weights方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • 用python實(shí)現(xiàn)PDF解密打印文件

    用python實(shí)現(xiàn)PDF解密打印文件

    大家好,本篇文章主要講的是用python實(shí)現(xiàn)PDF解密打印文件,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02
  • python下實(shí)現(xiàn)二叉堆以及堆排序的示例

    python下實(shí)現(xiàn)二叉堆以及堆排序的示例

    下面小編就為大家?guī)硪黄猵ython下實(shí)現(xiàn)二叉堆以及堆排序的示例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-09-09

最新評論

东兰县| 潼关县| 珲春市| 六安市| 越西县| 伽师县| 开封县| 河池市| 庆城县| 九寨沟县| 咸宁市| 贞丰县| 琼海市| 同江市| 扎赉特旗| 常州市| 松滋市| 丰镇市| 和平县| 修武县| 九龙县| 长垣县| 呼玛县| 策勒县| 尉犁县| 阳城县| 繁峙县| 互助| 克山县| 加查县| 芮城县| 武隆县| 漯河市| 虎林市| 钦州市| 永仁县| 紫金县| 阳泉市| 古田县| 丹棱县| 枣阳市|