mojado
mojado

Reputation: 390

selenium filter out _blank, which opens new tab

I got some problems with selenium on python.

Currently, I am using driver.find_elements_by_xpath("//a[@href]") to get all web elements with an href. However, there are some hrefs with target=“_blank”, cousing selenum to open a new tab, which I dont want.

Is it possible to filter out those elements somehow?

Upvotes: 0

Views: 48

Answers (1)

Svetlana Levinsohn
Svetlana Levinsohn

Reputation: 1556

You can try to filter them out by modifying your xpath, this should make it:

driver.find_elements_by_xpath("//a[@href and not(@target='_blank')]")

Good luck!

Upvotes: 1

Related Questions