I am writing small python script to open a webpage and click a link which redirects to next page. I have to then click export button which downloads the file.
When the control goes to second webpage, I get error “unable to locate the element”.
I am unable to print the list of elements in that page.
Here is the code snippet to change the window and getting all the elements in the second window
original_window = driver.current_window_handle
assert len(driver.window_handles) == 1
driver.find_element(By.XPATH, "//a[normalize-space()='Devices By Machine / Login Name']").click()
time.sleep(1)
handles = driver.window_handles
print(handles)
print(handles[1])
driver.switch_to.window(handles[1])
time.sleep(1)
print(driver.current_url)
print(driver.title)
time.sleep(20)
all_elements = driver.find_elements(By.TAG_NAME, "div")
for element in all_elements:
print(element.text)
buton = driver.find_element(By.XPATH, "//td[@id='PDFButton']//a[contains(text(), 'PDF')]").click()
Sangeetha Gowda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.