Example #1
0
# Create a new instance of the Firefox driver
driver = WebDriver(
    executable_path='/opt/phantomjs-2.1.1-linux-x86_64/bin/phantomjs',
    port=5001)

# go to the google home page
driver.get("http://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_id("kw")

# 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)
    print(driver.get_cookies())

finally:
    driver.quit()