Reputation: 21
I am working on a selenium project in Python where I am automating an online product ordering from https://www.flipkart.com/. I searched for a product(protein supplement in my case). Now when I am clicking on that product, details are now opening in a new tab with buying option there. But I don't have access to the DOM of that tab because I was working with the main page only. I am attaching two images along with code so that you can get my point.enter image description here
This is my code where I automated the process to click on the product-
def select_product(self):
element = self.find_elements_by_css_selector("div[class='_4ddWXP']")
self.refresh()
try :
element[0].click()
except StaleElementReferenceException :
element = self.find_elements_by_css_selector("div[class='_4ddWXP']")
element[0].click()
Please tell me how to proceed further. My main aim is to order that product.
Upvotes: 0
Views: 40
Reputation: 29382
You need to switch to new tab
in order to proceed further. The below code
you can write
once you click on product
which will land you on new tab
.
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1])
new tab
will have different handle
, so Selenium has to switch to new tab
.
Upvotes: 1