Hi everyone,
I tried a recent post and got no response. Hope that I have better
luck this time.
I am new to selenium and am using Yahoo Mail as my practice
application by trying to add a New Contact to my Yahoo email account.
When you get into Yahoo mail, you can then click a Contact tab which
makes a New Contact button visible ( I am assuming that this is done
by Ajax). When I run the test in webdriver, I can see the Contact tab
being clicked and am able to click the New Contact button which makes
all the input fields visible for the contact information. However when
I attempt to enter data in the first field called Nickname, selenium
is not able to find the field using xpath. I was able to find the
xpath fields using the Xpather tool.
Is it possible that the fields are in a different page or frame? If
so, I am not sure how to specify the new page or new frame.
Can someone with more experience please tell me what I am doing wrong.
I would very much appreciate any help.
Below is the selenium test case that was exported to Python:
from selenium import webdriver
from
selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
import unittest, time, re
class YahooCreateContact1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "
http://www.yahoo.com/"
self.verificationErrors = []
def test_yahoo_create_contact1(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_xpath("//li[@id='pa-u_14782488-bd']/a/
span[2]").click()
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("
xxx...@yahoo.com")
driver.find_element_by_id("passwd").clear()
driver.find_element_by_id("passwd").send_keys("yyyyyyyyy")
driver.find_element_by_id(".save").click()
# Click on the Contacts tab
driver.find_element_by_xpath("//a[@id='tabcontacts']/
b").click()
time.sleep(5)
# driver.find_element_by_link_text("New Contact").click()
# Wait until the New Contact button is visible
for i in range(60):
try:
if driver.find_element_by_xpath("//*[@id='toolbar']/
div[1]/span[1]/a").is_displayed(): break
except: pass
time.sleep(1)
else: self.fail("time out" )
driver.find_element_by_xpath("//*[@id='toolbar']/div[1]/
span[1]/a").click()
print "New Contact has been clicked"
# Wait for the Nick Name field to be visible
for i in range(60):
try:
if driver.find_element_by_xpath("//
*[@id='nickname:nickname:']/div/input").is_displayed(): break
except: pass
time.sleep(1)
else: self.fail("time out" )
driver.find_element_by_xpath("//*[@id='nickname:nickname:']/
div/input").clear()
driver.find_element_by_xpath("//*[@id='nickname:nickname:']/
div/input").send_keys("Jimmy")
driver.find_element_by_xpath("//*[@id='email:email:']/
input").clear()
driver.find_element_by_xpath("//*[@id='email:email:']/
input").send_keys("
jwi...@hotmail.com")
driver.find_element_by_xpath("//*[@id='phone:phone:']/
input").clear()
driver.find_element_by_xpath("//*[@id='phone:phone:']/
input").send_keys("
908-668-1368")
driver.find_element_by_xpath("//*[@id='saveAction']/
a").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
Here is the output from the test execution itself from the python
shell:
New Contact has been clicked
E
======================================================================
ERROR: test_yahoo_create_contact1 (__main__.YahooCreateContact1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\PythonPrograms\SeleniumTestCases
\YahooCreateContact.py", line 37, in test_yahoo_create_contact1
driver.find_element_by_xpath("//*[@id='nickname:nickname:']/div/
input").clear()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote
\webdriver.py", line 190, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote
\webdriver.py", line 525, in find_element
{'using': by, 'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote
\webdriver.py", line 144, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote
\errorhandler.py", line 118, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u'Unable to locate element:
{"method":"xpath","selector":"//*[@id=\'nickname:nickname:\']/div/
input"}' ; Stacktrace: Method WebDriverError threw an error in
file:///c:/docume~1/ron/locals~1/temp/tmp2ifs6g/extensions/
fxdr...@googlecode.com/resource/modules/utils.js
----------------------------------------------------------------------
Ran 1 test in 67.266s
FAILED (errors=1)
Traceback (most recent call last):
File "C:\Python27\PythonPrograms\SeleniumTestCases
\YahooCreateContact.py", line 67, in <module>
unittest.main()
File "C:\Python27\lib\unittest\main.py", line 95, in __init__
self.runTests()
File "C:\Python27\lib\unittest\main.py", line 231, in runTests
sys.exit(not self.result.wasSuccessful())
SystemExit: True