0

I am trying to open a link in a new tab,that particular link is present in webpage. All the examples i have seen online seems to send the link directly in code and open that link in a new tab rather than getting it dynamically

Changerequest is the link i want open in a new tab and closing the new tab after doing some function

Sourcecontrol = driver.find_element_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]')
   Sourcecontrol.click();
   Changerequest=driver.find_element_by_xpath( '//td[@class="confluenceTd"]/a[contains(.,"Change: ")]').send_keys(Keys.CONTROL + 't');
   #testvalue = Changerequest.get_attribute('href')
   driver.execute_script("window.open(Changerequest)")

When i use the short cut keys nothing seems to happen

send_keys(Keys.CONTROL + 't')
1
  • CTRL+T opens a new blank tab, it won't open a specific URL in that tab. You could open the new tab and then set the desired URL. You might try SHIFT+clicking the link as I think that might work in some browsers but I haven't tried it myself and it may depend on the browser. Commented Jul 29, 2019 at 18:45

1 Answer 1

2

Here is the solution.

Sourcecontrol = driver.find_element_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]')
Sourcecontrol.click();
Changerequest=driver.find_element_by_xpath( '//td[@class="confluenceTd"]/a[contains(.,"Change: ")]')
testvalue = Changerequest.get_attribute('href')
driver.execute_script("window.open(arguments[0])",testvalue)
Sign up to request clarification or add additional context in comments.

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.