[PYTHON] selenium

UI test automation with selenium + firefox

import time
import unittest

#pip install selenium
#brew install geckodriver
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


class PythonOrgTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()

    def tearDown(self):
        self.driver.close()

    def test_python_org(self):
        self.driver.get('http://www.python.org')
        self.assertIn('Python',self.driver.title)
        self.driver.find_element_by_link_text('Downloads').click()

        element = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.CLASS_NAME, 'widget-title')))
        self.assertEqual('Looking for a specific release?', element.text)

        self.driver.find_element_by_link_text('Documentation').click()

        element = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.CLASS_NAME, 'call-to-action')))
        self.assertIn('Browse the docs', element.text)

        element = self.driver.find_element_by_name('q')
        element.clear()
        element.send_keys('pycon')
        element.send_keys(Keys.RETURN)
        assert 'No results found' not in self.driver.page_source

Recommended Posts

selenium
Selenium, Phantomjs & BeautifulSoup4
Scraping with selenium
[Python / Selenium] XPath
Scraping with selenium ~ 2 ~
[Selenium] Version problem
phantomjs and selenium
Try using Selenium
Scraping with Selenium
Beginning with Selenium
Flash Selenium support
Successful scraping with Selenium
[Note] Selenium module introduced
selenium trick (proxy / headless)
How to debug selenium
ScreenShot with Selenium (Python)
Understand in 10 minutes Selenium
Selenium running in 15 minutes
Scraping with Selenium [Python]
Python web scraping selenium
python selenium chromedriver beautifulsoup