Talha Rajpoot
Talha Rajpoot

Reputation: 11

using selenium to interact with popup print dialogue box not working

I am trying to interact(set options like page size etc) on a print dialogue box that pops up after hitting a print button on a webpage. My attempt at the code is :

win_before = driver.current_window_handle
driver.find_element(By.XPATH,'/html/body/div/div/div1/div/div/main/div/div/div/div[2]/div/div/div[2]/button').click() # clicks the print button on webpage
time.sleep(2)
popup = 0
for handle in driver.window_handles:
   if handle != win_before:
      popup = handle
      break
driver.switch_to.window(popup)
time.sleep(5)
elem = driver.execute_script("return document.querySelector('print-preview-app')")
print(elem.get_attribute('innerHTML'))

at this point since the program has switched to the popped up dialogue box window , we should be able to interact with elements within the box using selenium methods but i have had no success. So i switched to using query selector this way and i still cannot locate any elements.
Html of the print dialogue box

Upvotes: 1

Views: 825

Answers (1)

Maire
Maire

Reputation: 31

Have you tried using alerts, it could be that the new window is an alert and swap to this something like Alert alert = driver.switchTo().alert(); instead of a browser window. If it is a browser element you could try Actions or javascript to move to the element before clicking and working with this element. Sorry if this isn't what you need - hope this helps.

Upvotes: 0

Related Questions