I am trying to automate credential validation using Python/Selenium. The target web-page is in the below mentioned code block.
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
b = webdriver.Chrome('chromedriver.exe')
b.get('http://220.156.189.33/esamudraUI/jsp/examination/checker/COCSearch.jsp?hidProcessId=COC')
parent = b.current_window_handle
# Clicking on the Calendar icon to enter date:
b.find_element_by_xpath(
'/html/body/form/table[4]/tbody/tr/td/table/tbody/tr[2]/td[3]/table/tbody/tr[5]/td[2]/span/a/font/b/img').click()
# Switching to the pop-up calendar window:
child = b.window_handles[1]
b.switch_to_window(child)
# Selecting month and year from drop-down:
month = Select(b.find_element_by_name('month'))
month.select_by_value('11')
year = Select(b.find_element_by_name('year'))
year.select_by_value('1986')
# Clicking on the required day in the table:
table = b.find_element_by_xpath('/html/body/form/table/tbody/tr[2]/td/table')
tags = table.find_elements_by_tag_name("td")
for tag in tags:
if tag.text == '3':
tag.click()
However, as soon as the code completes execution, NoSuchWindowException
is thrown.
---------------------------------------------------------------------------
NoSuchWindowException Traceback (most recent call last)
<ipython-input-184-94324ee00e42> in <module>
19 if tag.text == '3':
20 tag.click()
---> 21 b.close()
22 # while True:
23 # try:
~\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in close(self)
686 driver.close()
687 """
--> 688 self.execute(Command.CLOSE)
689
690 def quit(self):
~\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
319 response = self.command_executor.execute(driver_command, params)
320 if response:
--> 321 self.error_handler.check_response(response)
322 response['value'] = self._unwrap_value(
323 response.get('value', None))
~\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
240 alert_text = value['alert'].get('text')
241 raise exception_class(message, screen, stacktrace, alert_text)
--> 242 raise exception_class(message, screen, stacktrace)
243
244 def _value_or_default(self, obj, key, default):
NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=83.0.4103.116)
I tried using WebDriverWait(b, 5).until(EC.number_of_windows_to_be(1))
after tag.click() in the last line of the code, but the Exception remains.
I checked the class-method click()
under WebElement
class under Selenium web-driver but I got no clue on how to remove this exception:
def click(self):
"""Clicks the element."""
self._execute(Command.CLICK_ELEMENT)
Kindly give some advice.