diff --git a/docs/elements-in-the-page.rst b/docs/elements-in-the-page.rst index ce58d8b6e..17aa6c4d7 100644 --- a/docs/elements-in-the-page.rst +++ b/docs/elements-in-the-page.rst @@ -67,6 +67,14 @@ or browser.click_link_by_partial_text('part of link text') +or + +.. highlight:: python + +:: + + browser.click_link_by_id('link_id') + Clicking buttons ---------------- diff --git a/splinter/driver/__init__.py b/splinter/driver/__init__.py index ae4edbbfc..c4912d215 100644 --- a/splinter/driver/__init__.py +++ b/splinter/driver/__init__.py @@ -330,6 +330,12 @@ def click_link_by_partial_text(self, partial_text): """ return self.find_link_by_partial_text(partial_text).first.click() + def click_link_by_id(self, id): + """ + Clicks in a link by id. + """ + return self.find_by_id(id).first.click() + def quit(self): """ Quits the browser, closing its windows (if it has one). diff --git a/tests/click_elements.py b/tests/click_elements.py index 21dcbdac7..5db4d6d7c 100644 --- a/tests/click_elements.py +++ b/tests/click_elements.py @@ -34,3 +34,7 @@ def test_click_link_by_text(self): def test_click_link_by_partial_text(self): self.browser.click_link_by_partial_text("wordier") self.assertIn("BAR!", self.browser.html) + + def test_click_link_by_id(self): + self.browser.click_link_by_id('foo') + self.assertIn("BAR!", self.browser.html) diff --git a/tests/static/index.html b/tests/static/index.html index 541da474e..cbee17ccd 100644 --- a/tests/static/index.html +++ b/tests/static/index.html @@ -129,7 +129,7 @@