-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix erro in webelemet not created, verifing if is str or dict. #3481
Conversation
fix the problem when the element is string or dict.
Reducing the impact of change.
Fix error in webelemet not created, verifing if is str or dict. Tested in Firefox 51.0.1 e Chrome 55. |
@@ -95,6 +95,8 @@ def __call__(self, ignored): | |||
|
|||
|
|||
def _element_if_visible(element, visibility=True): | |||
if isinstance(element, str) or isinstance(element, dict): | |||
raise StaleElementReferenceException("Invalid locator") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the right exception class. There is an InvalidSelectorException class that covers bad locators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have problem because element not is webelement is str in firefox and dict in chrome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<selenium.webdriver.remote.webelement.WebElement (session="49274937103ea6cd11bc1c9a3a4784ee", element="0.9158218795761794-1")>
<selenium.webdriver.remote.webelement.WebElement (session="49274937103ea6cd11bc1c9a3a4784ee", element="0.9158218795761794-2")>
Traceback (most recent call last):
File "D:\Dropbox\Dropbox\Meu Curso de Selenium\testes\loading_page.py", line 30, in
test = wait_element_not_present(driver, ".loadingoverlay")
File "D:\Dropbox\Dropbox\Meu Curso de Selenium\testes\loading_page.py", line 20, in wait_element_not_present
expected_conditions.invisibility_of_element_located((By.CSS_SELECTOR, elem))
File "C:\Python35-32\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
value = method(self._driver)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 198, in call
return _element_if_visible(_find_element(driver, self.locator), False)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 100, in _element_if_visible
return element if element.is_displayed() == visibility else False
AttributeError: 'dict' object has no attribute 'is_displayed'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that happening? That function is a 'private' function that should only be called when there's an element to examine from the public expected condition functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This InvalidSelectorException not work because function need return true, do you look exception:
class invisibility_of_element_located(object):
""" An Expectation for checking that an element is either invisible or not
present on the DOM.
locator used to find the element
"""
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
try:
return _element_if_visible(_find_element(driver, self.locator), False)
except (NoSuchElementException, StaleElementReferenceException):
# In the case of NoSuchElement, returns true because the element is
# not present in DOM. The try block checks if the element is present
# but is invisible.
# In the case of StaleElementReference, returns true because stale
# element reference implies that element is no longer visible.
return True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you test if I'm wrong or right? How should I make the above code work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested the code you wrote on a simple web page. What you wrote seems like it should work, except in the case of waiting for an element to go 'invisible' you should not care about the result (The result will be True for invisibility). Maybe you should go to the #selenium chat room on freenode IRC and ask for help there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This problem only happen in invisibility_of_element_located, no have problem that return true or false, but the problem is that it throws an exception in the code and stop my test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I know if the problem came from chrome or firefox? How do I test this?
I don't think this is the right level to put a type check; what problem are you trying to solve? |
NoSuchElementException adding
|
@AutomatedTester I don't think this should have been merged. Clearly the function expects a web element type to have the is displayed function and it throws an exception. Either we add type checking for all expected condition functions for consistency and safety, or let python do its thing. That being said I have seen cases were Chrome or Firefox does not return a proper WebElement object but that's probably a bug in the driver. |
X
in the preceding checkbox, I verify that I have signed the Contributor License AgreementThis change is