1 Star 0 Fork 0

wtsnwei / learning-selenium-with-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_remote.py 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
wtsnwei 提交于 2021-01-11 10:01 . first commit
import unittest
from selenium import webdriver
class SearchProducts(unittest.TestCase):
def setUp(self):
firefox_options = webdriver.FirefoxOptions()
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
options=firefox_options
)
self.driver.get("http://demo-store.seleniumacademy.com/")
self.driver.implicitly_wait(30)
def tearDown(self):
self.driver.quit()
def test_search_by_category(self):
# get the search textbox
self.search_field = self.driver.find_element_by_name("q")
self.search_field.clear()
# enter search keyword and submit
self.search_field.send_keys('books')
self.search_field.submit()
# get all the anchor elements which have product names
# displayed currently on result page using # find_elements_by_xpath method
products = self.driver.find_elements_by_xpath("//h2[@class='product-name']/a")
# check count of products shown in results
self.assertEqual(3, len(products))
if __name__ == "__main__":
unittest.main()
Python
1
https://gitee.com/wtsnwei/learning-selenium-with-python.git
git@gitee.com:wtsnwei/learning-selenium-with-python.git
wtsnwei
learning-selenium-with-python
learning-selenium-with-python
master

搜索帮助