I am using Selenium in python. I have lists of hyperlinks from where I am iterating over each hyperlink and opening that particular link in a new tab and then put focus on new tab using Keys.CONTROL + Keys.SHIFT + Keys.RETURN.
Unfortunately, opening a link in new Tab fails while using xpath selection on the new tab:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from time import sleep
list_links = self.driver(By.XPATH, "//a/" )
for link in list_links:
link.send_keys(Keys.CONTROL + Keys.SHIFT + Keys.RETURN) #Open new Tab
#get text from new tab webpage.
sleep(50)
data = self.driver.find_element(By.XPATH, "//span/" ).text #ERROR
print data
I am able to open new tab and set focus the new tab (this appears to work). But when I try to use XPath on new tab then it throws:
NoSuchElementException: Message: no such element.
Even though the element is available there. I don't know what I am doing wrong here. Any help will be appreciable.