how to wait for an iframe to load in selenium pyth

2019-05-11 16:18发布

Script for page to get is

 from selenium import webdriver
        from selenium.webdriver.support.ui import WebDriverWait
        from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
        from selenium.webdriver.support import expected_conditions as EC
        import unittest     
        import time, re, castro
        class  LoginTest(unittest.TestCase):

            def setUp(self):
                self.driver = webdriver.PhantomJS()
                self.driver.maximize_window()
                self.driver.get("xxx.html") # getting the page
                "wanna wait her"
                print self.driver.save_screenshot("fire.png")

            def tearDown(self):     
                self.driver.quit()

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

HTML Code for iframe:

<body>
    <iframe src="http://thunder/spidio.net/CF9F4DA6B7533431/devinfo/devdect   /d,,,_STN&pg=Post=&ckid=null&ord=123&p=mts&cid=0&pid=124" style="background-color: transparent; border : 0px none transparent; padding: 0px; overflow: hidden;" height="1" width"1">
    </iframe>
</body>

please let me know how to make selenium wait for this iframe to be loaded in phantomjs with selenium using python

1条回答
冷血范
2楼-- · 2019-05-11 16:49

You can use below code to wait until required iframe appears:

WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, "//iframe[starts-with(@src, 'http://thunder/spidio.net/CF9F4DA6B7533431/devinfo/devdect')]")))
查看更多
登录 后发表回答