1

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

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

Comments

1

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.