Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79438 > unrolled thread

Problems with selenium 2 and python 3.4.1

Started bynovozhiloffvadim@gmail.com
First post2014-10-22 05:12 -0700
Last post2014-10-22 05:12 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Problems with selenium 2 and python 3.4.1 novozhiloffvadim@gmail.com - 2014-10-22 05:12 -0700

#79438 — Problems with selenium 2 and python 3.4.1

Fromnovozhiloffvadim@gmail.com
Date2014-10-22 05:12 -0700
SubjectProblems with selenium 2 and python 3.4.1
Message-ID<a40df8fd-7957-4e41-9d9a-5a0bc6849eb5@googlegroups.com>
Hi all, i have a little problem. I have a simple automation to fill login form fields. Actually, it passes good, but there's the problem. I need to see actual output in my console after the script filled fields, like "Logged in successfully" or "Username not found". I tried many stuff, but nothing worked this way, my last try was while loop and it works great, but only when I have positive result. I wrote a second condition, but when I type incorrect data, it drives me crazy to see all these errors in my console. So here's the code and part of output, any help or thoughts would be appreciated.

<code>
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException

baseurl = "http://www.somesite/login"
email = input("Type an email: ")
password = input("Type a password: ")

xpaths = { 'loginBox' : "//input[@id='session_email']",
           'passwordBox' : "//input[@id='session_password']",
           'submitButton' :   "//input[@class='ufs-but']",
           'success' : "//div[@class='flash-message success']",
           'error' : "//span[@class='form_error']"
         }


mydriver = webdriver.Firefox()
mydriver.get(baseurl)


mydriver.find_element_by_xpath(xpaths['loginBox']).send_keys(email)


mydriver.find_element_by_xpath(xpaths['passwordBox']).send_keys(password)


mydriver.find_element_by_xpath(xpaths['submitButton']).click()


while mydriver.find_element_by_xpath(xpaths['success']):
	print("Success")
	if mydriver.find_element_by_xpath(xpaths['error']):
		print("No")
</code>

And there's what I got when I try to interrupt an error:

File "ab.py", line 32, in <module>
    while mydriver.find_element_by_xpath(xpaths['success']):
  File "/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/webdriver.py", line 230, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/webdriver.py", line 662, in find_element
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/webdriver.py", line 173, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/errorhandler.py", line 166, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate element: {"method":"xpath","selector":"//div[@class=\'flash-message success\']"}' ; Stacktrace: 
    at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpjax8kj1u/extensions/fxdriver@googlecode.com/components/driver-component.js:9618:26)
    at FirefoxDriver.prototype.findElement (file:///tmp/tmpjax8kj1u/extensions/fxdriver@googlecode.com/components/driver-component.js:9627:3)
    at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpjax8kj1u/extensions/fxdriver@googlecode.com/components/command-processor.js:11612:16)
    at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpjax8kj1u/extensions/fxdriver@googlecode.com/components/command-processor.js:11617:7)
    at DelayedCommand.prototype.execute/< (file:///tmp/tmpjax8kj1u/extensions/fxdriver@googlecode.com/components/command-processor.js:11559:5) 

As I said, successfull result ain't a problem. Hope to get any help.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web