Selenium Unsupported command selectWindow

208 views Asked by At

I am seeking to automate the selection, execution, and downloading of data (as CSV) from a public website using selenium. The process has been recorded using the Katalon Recorder plugin for Chrome and exported to a python script. When I run the script, it fails to complete as it appears there are two (as yet) unhandled errors:

    def test_eudra_vigelence_a_z_covid_download(self):
        driver = self.driver
        driver.get("http://www.adrreports.eu/en/search_subst.html")
        driver.find_element_by_link_text("C").click()
        driver.find_element_by_link_text("COVID-19 VACCINE ASTRAZENECA (CHADOX1 NCOV-19)").click()
        # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_1 | ]]
        driver.find_element_by_xpath("//table[@id='dashboard_page_6_tab']/tbody/tr/td[2]/div").click()
        driver.find_element_by_id("saw_1744933_a_1_dropdownIcon").click()
        driver.find_element_by_id("saw_1744933_a_1_ck0").click()
        driver.find_element_by_id("saw_1744933_10_1_dropdownIcon").click()
        driver.find_element_by_id("saw_1745105_c_1_dropdownIcon").click()
        driver.find_element_by_xpath("//div[8]/div/div[2]/div/span").click()
        driver.find_element_by_link_text("Run Line Listing Report").click()
        # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_2 | ]]
        driver.find_element_by_link_text("Export").click()
        driver.find_element_by_xpath("(//a[@id='popupMenuItem']/table/tbody/tr/td[2])[7]").click()
        driver.find_element_by_link_text("OK").click()

Has anyone seen these issues before, and what was the solution to add the Selenium code to correct the process?

1

There are 1 answers

1
cruisepandey On

Well there's a tab switch, you would need to switch the focus of web driver to the newly switched windows :

Code :

driver = webdriver.Chrome("C:\\Users\\Python\\Desktop\\Selenium+Python\\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("http://www.adrreports.eu/en/search_subst.html")
driver.find_element_by_link_text("C").click()
windows_before  = driver.current_window_handle
driver.execute_script("window.scrollTo(0, 250)")
wait.until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, 'COVID-19 VACCINE ASTRAZENECA'))).click()
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))
windows_after = driver.window_handles
new_window = [x for x in windows_after if x != windows_before][0]
driver.switch_to.window(new_window)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "td[class*='obipsTabBarToolbarCell'] img[alt='More Tab']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Line Listing']"))).click()

for your second issue there's again a tab switch so before clicking on Run Line Listing Report link save windows handles just like how I have done it and then switch to new tab.