Selenium Webdriver failed when use window_handles
<p>I am trying to handle Two Tab in Python Selenium webdriver with Chrome as browser.</p>

<p>I am getting result for find element by link text on first tab as well as second tab if I keep the <strong>Chrome Browser as selected window</strong>.[i.e Front Screen Process ]</p>

<p>When I change the control to new tab using</p>

<pre><code>driver.switch_to_window(driver.window_handles[1])
</code></pre>

<p>and minimise the google chrome[i.e if I select any process other than Google Chrome].i get the error in finding the link text saying <strong>Element Not Found Exception</strong> for Second Tab only not on first Tab.</p>

<p>I am getting result on First Tab.</p>

<pre><code>def DriverCreation():
    try:
        Driver = WebBase.initWebScraping(URL)   # Methods visible Driver.driver and Driver.loggerDriverWait = Driver.EC
        print "Driver Creation Successful"
        return Driver
    except:
        print "Driver Initalisation Failed"
        sys.exit(1)
if __name__ == '__main__':
    URL = 'https://www.example.com/'
    Driver = DriverCreation() # will Load first Tab with www.Example.com
    aboutlink = Driver.driver.find_element_by_link_text('about')
    aboutlink.send_keys(Keys.CONTROL + Keys.RETURN)
    Driver.driver.switch_to_window(Driver.driver.window_handles[1])
    contactLink =  Driver.driver.find_element_by_link_text('contact')
    print contactLink.text()  #** getting error if i change the focus from Google Chrome and works fine if i keep the window focus on Google Chrome**
</code></pre>

<p>you can manage tab using following code.</p>

<pre><code>driver.execute_script("window.open('"+url+"', '_blank');")
driver.switch_to_window(driver.window_handles[1])
</code></pre>

python google-chrome selenium selenium-webdriver windows-7