Solved

Python Selenium Webdriver Login Issues On Mac

Posted on 2016-08-19
5
79 Views
Last Modified: 2016-11-15
I had this question after viewing Using Python To Iterate Through All Website Pages And Paste Changed Content Back.

I am able to open https://www.blogger.com/about/ but then I need to click on the SIGN IN link at the top right of the screen and then insert my username and password but keep getting strange errors.  I am using Python 3.3.6 and Selenium 2.53.6

I am getting this error in my code
File "expertsBrazil2webdriver.py", line 16, in <module>
    driver.findElement (By.linkText("SIGN IN")).click()
AttributeError: 'WebDriver' object has no attribute 'findElement'

Open in new window


Here is the code I am using
from selenium import webdriver
from selenium.webdriver.common.proxy import *
import traceback
import random
import os
import time

os.environ["SELENIUM_SERVER_JAR"] = "/Users/rjw/Documents/Python/selenium-server-standalone-3$

browser = None
try:
  # browser = webdriver.Firefox()
    driver = webdriver.Safari()
    driver.get('https://www.blogger.com/about/')   # navigate to your blog
    time.sleep(5)
    driver.findElement (By.linkText("SIGN IN")).click()
except:
    print(traceback.format_exc())
finally:
    if browser:
        browser.quit()

Open in new window

0
Comment
Question by:sharingsunshine
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 41763464
The correct method is find_element not findElement.
Example from Selenium Documentation:
cheese = driver.find_element(By.LINK_TEXT, "cheese")

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41763622
I am getting this error  

 File "expertsBrazil2webdriver.py", line 16, in <module>
    SIGN_IN = driver.find_element(By.LINK_TEXT, "SIGN IN")
NameError: name 'By' is not defined

Open in new window

0
 
LVL 15

Accepted Solution

by:
Walter Ritzel earned 500 total points
ID: 41763824
Add this line on your import section:
from selenium.webdriver.common.by import By

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41763877
that was right on.  As always, great help you give.
0
 

Expert Comment

by:Ranadheer Kurakula
ID: 41887721
You can actually use  
driver.find_element_by_link_text('SIGN IN').click()

Open in new window

This will work fine.
1

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now