How to get url from a new window by using Selenium with phantomjs
Question: I want to get a new window url by using selenium, and using PhantomJs is more
efficient than Firefox. python code is here:

    
    
    from selenium import webdriver
    renren = webdriver.Firefox()
    #renren = webdriver.PhantomJS()
    renren.get("file:///home/xjz/Desktop/html/easy.html")
    renren.execute_script("windows()")
    now_handle1 = renren.current_window_handle
    all_handles1 = renren.window_handles
    for handle1 in all_handles1:
        if handle1 != now_handle1:
            renren.switch_to_window(handle1)
            print renren.current_url
            print renren.page_source
    

In script "windows()", it will open a new window for <http://www.renren.com/>.
When I use Firefox,I get current url and context of <http://www.renren.com/> .
But I get "about:blank" of the url and "" of the context.It means I get failed
when I use PhantomJS. So how can I get current url when I use selenium with
PhantomJS. Thanks a lot.


Answer: You can add sleep time in your code before getting the current URL.

    
    
    from selenium import webdriver
    renren = webdriver.Firefox()
    ...
    ...
    ...
    import time
        time.sleep(10)# in seconds
        print renren.current_url
    ..
    

