Web自動化測試載入器——Selenium

來源:互聯網
上載者:User

標籤:python   selenium   自動化測試   web   chrome   

在最近的Web課程設計上我接觸到了Selenium這款Web自動化測試載入器,它可以通過一系列find_element()方法定位到目標元素,對其發送類比按鍵動作,使操作自動化。


首先,使用pip安裝Selenium的Python模組。

下面是我寫的常式。find_element_by_name方法就是通過name屬性來定位元素,然後通過send_keys()發送類比按鍵。基於這樣的操作基本可以完成各種web下的類比操作。

import timefrom selenium import webdriverfrom selenium.webdriver.common.keys import Keyschrome_driver_path = "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/chromedriver"driver = webdriver.Chrome(chrome_driver_path)driver.get("http://localhost:8000/")driver.get("http://localhost:8000/login")assert "Bookstore" in driver.titleelem_username = driver.find_element_by_name("username")elem_username.send_keys("tiger1")elem_password = driver.find_element_by_name("password")elem_password.send_keys("tiger1")elem_password.send_keys(Keys.RETURN)time.sleep(5)driver.close()



如果遇到以下錯誤

selenium.common.exceptions.WebDriverException: Message: ‘ChromeDriver executable needs to be available in the path.

解決方案在http://selenium-python.readthedocs.org/faq.html#how-to-use-chromedriver

Web自動化測試載入器——Selenium

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.