开发者

Selenium script can't find function when opening new page

I have a problem with my selenium-python script when opening another page in separate function.

In function test2_points() selenium can't find functionselect and Products_4.

This is my script:

from selenium import selenium
import unittest, time, re
import socket
import sys

class discount_reward(unittest.TestCase):
    def setUp(self):
         print "setUp invoked"
         self.port               = "4444"
         self.ip_address         = "localhost"
         self.browser            = "*chrome"#firefox
         self.base_url           = "http://128.0.0.1:1062"
         self.browser_title      = "Hammer"
         self.verificationErrors = []

         try:
            print "starting selenium with the following parameters:"
            print "ip address:  %s\nport:  %s\nbrowser:  %s\nbase_url:  %s" %(self.ip_address, self.port, self.browser, self.base_url)
            self.selenium = selenium(self.ip_address, self.port, self.browser, self.base_url)
            self.selenium.start()

         except socket.error, error:
            print "\nSocket Exception: %s" %(error)
            print "\nCould not connect to %s:%s with browser %s" %(self.base_url, self.port, self.browser)
            sys.exit(1)

    def test1_discount_reward(self):
        sel = self.selenium
        sel.open("/Hammer/offer-rew-discount.aspx?开发者_如何学Python")
        sel.select("functionselect", "label=Products_2")
        sel.click("select1")
    def test2_points_reward(self):
        sel = self.selenium
        sel.open("/Hammer/offer-rew-points.aspx?")
        sel.select("functionselect", "label=Products_4")
        sel.click("select1")

    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

Can anyone tell me what's wrong?


You're almost certainly executing that sel.select() before the page is finished loading. Any time you perform an action that causes a page transition (e.g., open(), click() on a link or button), you should follow it with a wait_for_page_to_load(timeout_in_milliseconds). The wait will end when the page is fully loaded into the browser, or will time out (which is obviously an error condition).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜