Python Test Script:
from selenium import selenium
import unittest, time, re
class test_link_to_blank(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "file:///D:/code/selenium/sandpit/new-window/base-page-blank.html")
self.selenium.start()
def test_test_link_to_blank(self):
sel = self.selenium
sel.open("file:///D:/code/selenium/sandpit/new-window/base-page-blank.html")
self.assertEqual("Base Page Blank", sel.get_title())
try: self.failUnless(sel.is_text_present("Base Page Blank"))
except AssertionError, e: self.verificationErrors.append(str(e))
sel.click("link=Link")
sel.select_window("title=Pop Up Window")
self.assertEqual("Pop Up Window", sel.get_title())
try: self.failUnless(sel.is_text_present("Pop Up Window"))
except AssertionError, e: self.verificationErrors.append(str(e))
sel.close()
sel.select_window("null")
self.assertEqual("Base Page Blank", sel.get_title())
try: self.failUnless(sel.is_text_present("Base Page Blank"))
except AssertionError, e: self.verificationErrors.append(str(e))
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
base-page-blank.html:
<html>
<head>
<title>Base Page Blank</title>
</head>
<body>
<p>Base Page Blank</p>
<p><a href="popup.html" target="_blank">Link</a></p>
</body>
</html>
popup.html:
<html>
<head>
<title>Pop Up Window</title>
</head>
<body>
<p>Pop Up Window</p>
</body>
6 comments:
Thanks a millions Dave. It worked for me at last. This is fantastic.
Hi Dave,
first - thanks a lot for sharing your knowledge. it's really helpful.
I tried your solution with selecting new windows with selenium. It only works for me when I'm using button with window.open. when i try and a link with href - it never works.
do you know why?
thanks a lot.
Joe
Hi Joe,
Sorry I don't
thanks for your time and effort.
hi,
maybe you can help - I'm trying to use selenium with xpath to activate a link on the page(locator).
this is basically the HTML -
list item
definition list class=class1
item in a definition list(text=same text)
describe an item
list item
definition list class=class2
item in a definition list(text=same text)
describe an item
definition list class=class3
item in a definition list(text=other text)
describe an item
unordered list class=class3
list item class=class4
my link is here with the click function and some text
i needed to write the html as text - i failed validation when posting the comment...
I need to activate the link(click).
I know the classes and the texts.
any idea how to do it using xpath?
thanks in advance.
Post a Comment