tibbon
tibbon

Reputation: 1028

How do I click to open a link in new window with Selenium-webdriver in ruby?

So I've got a list of clickable links using selenium-webdriver in Ruby:

users = driver.find_elements(:class, "username")

of course, I can click on them.

users.first.click

But that opens it in the same window. I want to open it in a new window, load the window, and then close that window, so I don't lose track/context of additional links on the page. I can't find how to do this. The closest I have is

driver.execute_script("window.open('#{users.first}')")

But that doesn't extract a link from it, since its just a target to click on, not a URL. So I need to either extract the URL from the element, or have some other way to open a new window.

Upvotes: 1

Views: 829

Answers (1)

K M Rakibul Islam
K M Rakibul Islam

Reputation: 34336

try to add an option like: :target => "_blank"

Upvotes: 1

Related Questions