Reputation: 31
I am doing automation on a website.
I do a search on this site and your result returns a link for me to access, click it to open a new tab, but I want to open a new window
this is my code to click the link
WebDriverWait(self.browser, timeout=60).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tabelaResultado"]/div[1]/table/tbody[1]/tr/td[1]/span/a'))).click()
I tried using the SHIFT keyboard shortcut
WebDriverWait(self.browser, timeout=60).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tabelaResultado"]/div[1]/table/tbody[1]/tr/td[1]/span/a'))).send_keys(Keys.SHIFT).click()
but I have a result error
AttributeError: 'NoneType' object has no attribute 'click'
Is there a way I can configure chrome so every time I click a link it opens a new window?
from selenium.webdriver.chrome.options import Options
Upvotes: 1
Views: 425
Reputation: 470
I think you have to write it like this by sending Shift and Enter:
WebDriverWait(self.browser, timeout=60).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tabelaResultado"]/div[1]/table/tbody[1]/tr/td[1]/span/a'))).send_keys(Keys.SHIFT,Keys.ENTER)
Upvotes: 2
Reputation: 50819
send_keys()
as no return value, so you are getting None
. You can do it with ActionChains
from selenium.webdriver import ActionChains
link = WebDriverWait(self.browser, timeout=60).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tabelaResultado"]/div[1]/table/tbody[1]/tr/td[1]/span/a')))
ActionChains(driver).key_down(Keys.SHIFT, link).click().key_up(Keys.SHIFT).perform()
Upvotes: 1