I am using Expected condition visibility_of_element_located(elementlocator) to check visibility in the webpage. But performance isn't good when an element is not visible in the page, please could someone help in improving the performance in the below code. The python code used is,
def check_for_visibility_of_the_element(self,locator,Timeout):
result=None
webelement=None
ignored_exceptions=('NoSuchElementException','StaleElementReferenceException')
if int(Timeout)==int(BuiltIn().get_variable_value("${EXPLICIT_WAIT_TIMEOUT}")):
if self.element == None:
self.element = WebDriverWait(self._driver, int(Timeout),ignored_exceptions=ignored_exceptions)
webelement=self.element
else:
webelement=self.element
else:
self.element = WebDriverWait(self._driver, int(Timeout),ignored_exceptions=ignored_exceptions)
webelement=self.element
self.element=None
elementlocator=self._getlocator(locator)
try:
webelement.until(EC.visibility_of_element_located(elementlocator))
except:
print('Unable to find the visibility of the element in given time')
return False
return True
${EXPLICIT_WAIT_TIMEOUT} is a variable that has 45 seconds as its value. The Robot keyword that uses this keyword is
Check if Element not visible
${status} ${value} Run Keyword And Ignore Error Element Should Be Visible ${Locator}
:FOR ${i} IN RANGE 1 20
\ ${Boolean}= check_for_visibility_of_the_element ${Locator} 1
\ Exit For Loop If ${Boolean}==False
The explicit wait time given is 1 second in the keyword check_for_visibility_of_the_element. In each iteration, the Webdriver waits for 1 second to check if the element is visible or not. But in my case, it is taking 15 seconds to check if the element is NOT visible in the webpage, even though the waiting period given is 1 second. how to fix this issue?
WebDriverWait
. – Bryan Oakleyvisibility_of_element_located
on an element that is not supposed to be visible. I might useinvisibility_of_element_located
instead. – Marcel Wilson