1

I just started using Selenium 2 tonight so this will be very basic (I hope...).

I am trying to log onto my account at http://contentparadise.com/

I go to the sign in page https://www.contentparadise.com/signin.aspx and am able to enter the id/pw, then submit. But even with the correct id/pw, it returns me to the signin page - with a small messagebox added with the words "The following error has occurred". Obviously the id/pw in the code is wrong, I'm trying to detect this as an error - but I get it even with my real id/pw.

How do I detect and read this messagebox, and why doesn't the correct set go to the home page?

I use the same code on another site, use the correct set, and it takes me to the home page as it should.

Is this a case of the signin page using javascript? If you look at the source for the signin page, look for the string "" to start that part of the form.

Here's the code:

from selenium import webdriver
import sys
import os

userID = "wajahbaru"
pw = "marmalade"

wdrv = webdriver.Firefox()
wdrv.get("https://www.contentparadise.com/signin.aspx")

print "Page #1 title is: " + wdrv.title; # should be "Sign In"

unamefield = wdrv.find_element_by_name("ctl00$ContentPlaceHolder1$txtUserName").send_keys(userID)
pwdfield = wdrv.find_element_by_name("ctl00$ContentPlaceHolder1$txtPassword").send_keys(pw)
pwdfield = wdrv.find_element_by_name("ctl00$ContentPlaceHolder1$btnLogin").click()

print "Page #2 title is: " + wdrv.title; # if logged in this should be "Content Paradise: Buy or Sell Software, 2D Content, 3D Models and Audio."

wdrv.get_screenshot_as_file("test.jpg")
wdrv.quit()
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
Stephen
  • 155
  • 2
  • 16

2 Answers2

1

How do I detect and read this messagebox, and why doesn't the correct set go to the home page?

To detect error messagebox you could search for element with id="error":

#!/usr/bin/env python
from contextlib import closing
from selenium.webdriver import Firefox as Browser
from selenium.webdriver.support.ui import WebDriverWait

timeout = 10 # seconds

with closing(Browser()) as browser:
    browser.get('https://www.contentparadise.com/signin.aspx')
    assert browser.title == "Sign In"
    login, password, submit = map(browser.find_element_by_id,
        ['ctl00_ContentPlaceHolder1_txtUserName',
         'ctl00_ContentPlaceHolder1_txtPassword',
         'ctl00_ContentPlaceHolder1_btnLogin'])
    enter_text = lambda x, text: (x.clear(), x.send_keys(text))
    enter_text(login, "abc")
    enter_text(password, "pas$W0rd")
    submit.click()

    # wait for error or success
    value = WebDriverWait(browser, timeout).until(
        lambda x: ("Content Paradise" in x.title and "ok" or
                   x.find_element_by_id('error')))
    if value != "ok":
       print "error:", value.text
    browser.get_screenshot_as_file('test.jpg')
jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • OK, that shows me the text of the alert - thanks. BTW, I am not getting email notices there was an answer... – Stephen Jan 22 '12 at 18:50
0

Search for "Popup dialogs" in the link below .. if you want to learn more, search for that code you find in Google, and you'll get some good stuff ;-)

http://readthedocs.org/docs/selenium-python/en/latest/navigating.html?highlight=popup

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
  • 4
    it is not very helpful to send people to google. StackOverflow is *the destination* google sends people to. – jfs Jan 22 '12 at 09:35