import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
class slTest(unittest.TestCase):
def test_santi(self):
self.browser=webdriver.Ie("C:\Users\chethan\Documents\IEDriverServer.exe")
self.browser.implicitly_wait(5)
self.browser.get("http://myqesite.com/banners.php")
#vr=self.browser.execute_script("return initValues")
curr=self.browser.current_window_handle
print curr
num=0
res=self.browser.find_element_by_id("productcontainer")
links=res.find_elements_by_tag_name("a")
for link in links:
link.click()
time.sleep(2)
open_windows = self.browser.window_handles
self.browser.switch_to_window(open_windows[-1])
print "current: ", self.browser.current_url
print link.get_attribute("id")
#print self.browser.current_url
num=num+1
print num
#self.browser.quit()
if __name__ == "__main__":
unittest.main()
点击每个链接后,将打开一个新窗口,需要通过使用switch_to_window来打开每个窗口的URL。
请有人帮我解决这个问题
提前致谢