I am using pyCharm Console for this demo:

from selenium import webdriver
browser = webdriver.Chrome()

If you get the following error:

Traceback (most recent call last):
File “<input>”, line 1, in <module>
File “/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/chrome/webdriver.py”, line 62, in __init__
self.service.start()
File “/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/common/service.py”, line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

The following error says chromedriver is not in your PATH.
Download it if you don’t have it and add it to your path, otherwise just set your path.

Go to the following site to the latest copy:
chromedriver

Check your path, and copy it to existing PATH directory or set it:

On Terminal:

echo $PATH
cp chromedriver $some_dir #to one of the paths returned in your terminal

OR on your console enter the following:

driver = webdriver.Chrome(‘/path/to/chromedriver’)

run command again:

browser = webdriver.Chrome()

Navigate to ilparle.com

browser.get(‘http://www.ilparle.com&#8217;)

screen-shot-2017-02-05-at-3-22-01-am

Inspect an element on the ilparle.com page.
screen-shot-2017-02-05-at-3-32-47-am

To the right the element is highlighted, copy the code as selector
Screen Shot 2017-02-05 at 3.33.38 AM.png

I select the”SSH tunnel on Toad”  link to inspect.
Paste to the Python “Copy Selector” text to the console ‘#post-572 > header > h2 > a’ to manipulate the link

elem = browser.find_element_by_css_selector(‘#post-572 > header > h2 > a’)

elem.text

‘SSH tunnel on Toad’

 

elem.click()

This takes you to the link you pointed to using the copied selector text.

Screen Shot 2017-02-05 at 3.23.19 AM.png

browser.quit()

Advertisements