So I am using a code to try to automatically generate monthly reports at my office, but I keep running into an issue where I get the "Unable to locate element" error.
I am using driver.find_element_by_xpath to navigate from page to page without any issues, until I finally come to the point when another tab is opened for me to start inputting the variables for the report-runner (i.e. Date range, customer names... etc).
I am using the following code to ensure that the driver is targeting the correct window:
windowbefore = driver.window_handles[0]
windowafter = driver.window_handles[1]
driver.switch_to.window(windowafter)
I print the current window handle of the tabs before & after the switch, and am able to confirm that I am working with the newly opened window as my code continues. At this point however I immediately get thrown the error stated above, regardless of which web element I try to interact with.
I am working with the Chrome driver, and all of the elements that I am working with seem to have an xpath associated with them. I have also set up several time.sleep() functions to make sure all web elements are available when each line executes.
Does anybody have any experience with a similar issue?