웹 자동화 테스트(2) Selenium 3은 IE, Firefox, Chrome 코드 예제를 시작합니다.

little bottle
풀어 주다: 2019-04-10 11:58:29
앞으로
1891명이 탐색했습니다.

Selenium은 웹 애플리케이션 테스트를 위한 도구입니다. Selenium 테스트는 실제 사용자와 마찬가지로 브라우저에서 직접 실행됩니다. "Web Automated Testing (2) "의 마지막 장에서는 주로 웹 테스트에서 Selenium 3가 사용하는 문제 세트와 솔루션에 대해 이야기했습니다. 이 문서에서는 주로 참조용으로 IE, Firefox 및 Chrome을 시작하기 위한 코드 예제에 대해 설명합니다.

IE, Firefox, Chrome을 시작하기 전에 해당 브라우저의 드라이버 서버를 Windows 시스템 경로 디렉터리로 설정해야 합니다.

예를 들어, 내 드라이버는 C:Program Files (x86)seleniumdriver 디렉터리에 있습니다. 다음은 Windows 시스템 경로 경로 설정입니다.

IE 코드 시작:

#!/usr/bin/env python
#coding=utf-8

from selenium import webdriver
import os
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

driver = webdriver.Ie()

# go to the google home page
driver.get("https://www.baidu.com/")

# the page is ajaxy so the title is originally this:
print driver.title

# find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("wd")

# type in the search
inputElement.send_keys("cheese!")

# submit the form (although google automatically searches now without submitting)
inputElement.submit()

try:
    # we have to wait for the page to refresh, the last thing that seems to be updated is the title
    WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))

    # You should see "cheese! - Google Search"
    print driver.title

finally:
    pass
    #driver.quit()
로그인 후 복사

FireFox 코드 시작: # 🎜🎜#

#!/usr/bin/env python
#coding=utf-8

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

# Create a new instance of the Firefox driver
#binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
#driver = webdriver.Firefox(firefox_binary=binary)

driver = webdriver.Firefox()

# go to the google home page
driver.get("https://www.baidu.com/")

# the page is ajaxy so the title is originally this:
print driver.title

# find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("wd")

# type in the search
inputElement.send_keys("cheese!")

# submit the form (although google automatically searches now without submitting)
inputElement.submit()

try:
    # we have to wait for the page to refresh, the last thing that seems to be updated is the title
    WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))

    # You should see "cheese! - Google Search"
    print driver.title

finally:
    pass
    #driver.quit()
로그인 후 복사


Chrome 코드 시작:

#!/usr/bin/env python
#coding=utf-8

from selenium import webdriver
import os
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

driver = webdriver.Chrome()

# go to the google home page
driver.get("https://www.baidu.com/")

# the page is ajaxy so the title is originally this:
print driver.title

# find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("wd")

# type in the search
inputElement.send_keys("cheese!!")

# submit the form (although google automatically searches now without submitting)
inputElement.submit()

try:
    # we have to wait for the page to refresh, the last thing that seems to be updated is the title
    WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))

    # You should see "cheese! - Google Search"
    print driver.title

finally:
    pass
    #driver.quit()
로그인 후 복사
[추천 과정:

Python 비디오 튜토리얼

위 내용은 웹 자동화 테스트(2) Selenium 3은 IE, Firefox, Chrome 코드 예제를 시작합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:csdn.net
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!