Skip to content

Commit

Permalink
Fix #169 - search of element based on hidden element (#170)
Browse files Browse the repository at this point in the history
* #169 add tests to reproduce bug

* #169 fix search from hidden element

* #169 fix tests in error_messages_test.py
  • Loading branch information
maratori authored and SergeyPirogov committed Jun 26, 2018
1 parent 696284e commit 012151d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
8 changes: 4 additions & 4 deletions selene/elements.py
Expand Up @@ -57,7 +57,7 @@ def description(self):

def find(self):
# return self._element.get_actual_webelement().find_element(*self._by)
return wait_for(self._element, be.visible, config.timeout, config.poll_during_waits).find_element(*self._by)
return wait_for(self._element, be.in_dom, config.timeout, config.poll_during_waits).find_element(*self._by)


class CachingWebElementLocator(ISeleneWebElementLocator):
Expand Down Expand Up @@ -121,7 +121,7 @@ def description(self):

def find(self):
# return self._element.get_actual_webelement().find_elements(*self._by)
return wait_for(self._element, be.visible, config.timeout, config.poll_during_waits) \
return wait_for(self._element, be.in_dom, config.timeout, config.poll_during_waits) \
.find_elements(*self._by)


Expand Down Expand Up @@ -396,13 +396,13 @@ def hover(self):
def find_elements(self, by=By.ID, value=None):
return self._execute_on_webelement(
lambda it: it.find_elements(by, value),
condition=be.visible)
condition=be.in_dom)
# return self.__delegate__.find_elements(by, value) # todo: remove

def find_element(self, by=By.ID, value=None):
return self._execute_on_webelement(
lambda it: it.find_element(by, value),
condition=be.visible)
condition=be.in_dom)
# return self.__delegate__.find_element(by, value) # todo: remove

# *** IWebElement methods ***
Expand Down
7 changes: 1 addition & 6 deletions tests/integration/error_messages_test.py
Expand Up @@ -104,11 +104,6 @@ def test_inner_selement_search_fails_with_message_when_implicitly_waits_for_cond
'to assert Visible',
"for first_by('css selector', '#hidden-container').find_by('css selector', '#button')",
'',
'reason: TimeoutException:',
'failed while waiting 0.1 seconds',
'to assert Visible',
"for first_by('css selector', '#hidden-container')",
'',
'reason: ConditionMismatchException: condition did not match',
'screenshot: //.selene/screenshots/*/screen_*.png']

Expand All @@ -131,7 +126,7 @@ def test_inner_selement_search_fails_with_message_when_implicitly_waits_for_cond
'',
'reason: TimeoutException:',
'failed while waiting 0.1 seconds',
'to assert Visible',
'to assert InDom',
"for first_by('css selector', '#not-existing')",
'',
'reason: NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#not-existing"}',
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/test_find_from_hidden_element.py
@@ -0,0 +1,34 @@
import os

from selene import config, browser
from selene.conditions import in_dom, hidden, text, size
from selene.support import by
from selene.support.jquery_style_selectors import s

start_page = 'file://' + os.path.abspath(os.path.dirname(__file__)) + '/../resources/start_page.html'


def setup_module(m):
config.browser_name = "chrome"
browser.open_url(start_page)
s("#hidden_button").should_be(in_dom).should_be(hidden)


def test_get_actual_hidden_webelement():
s("#hidden_button").get_actual_webelement()


def test_find_selenium_element_from_hidden_element():
s("#hidden_button").find_element(*by.be_following_sibling())


def test_find_selenium_elements_from_hidden_element():
s("#hidden_button").find_elements(*by.be_following_sibling())


def test_find_selene_element_from_hidden_element():
s("#hidden_button").following_sibling.should_have(text("Inner Link"))


def test_find_selene_collection_from_hidden_context():
s("#hidden_button").ss(by.be_following_sibling()).should_have(size(6))

0 comments on commit 012151d

Please sign in to comment.