How to write a test to verify using Selenium Web Browser Automation
I'm very new to Selenium Web Browser Automation. I'm trying to write a test to verify a that the menu item for About actually goes to the About page in "http://www.seleniumhq.org/" Do you guys have an idea of how to achieve this by using Selenium Web Browser Automation Python?? Thanks you!
找到通过链接文本的About
链接,点击它并检查driver.title
的值是什么:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.seleniumhq.org/")
driver.find_element_by_link_text("About").click()
assert driver.title == "About Selenium"
driver.close()
First, determine what(element,text,link,img etc) in the loaded about page you will use to validate that you are in correct(about) page. Then construct your code like this-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.set_page_load_timeout(10)
driver.get("http://www.seleniumhq.org")
driver.find_element_by_id("menu_about").click()
#Assertion 1
assert 'About' in driver.title
#Assertion 2
assert 'about' in driver.current_url
#console log
print('Title of the current page is: ' + driver.title)
print('Current URL is : ' + driver.current_url)
driver.close()
链接地址: http://www.djcxy.com/p/65336.html