SeleniumBase/examples/test_hack_search.py

31 lines
1.5 KiB
Python
Raw Normal View History

""" Testing the "self.set_attribute()" and "self.set_attributes()" methods
to modify a Google search into becoming a Bing search.
set_attribute() -> Modifies the attribute of the first matching element.
set_attributes() -> Modifies the attribute of all matching elements. """
from seleniumbase import BaseCase
2021-03-11 06:27:52 +08:00
class HackingTests(BaseCase):
def test_hack_search(self):
2022-06-11 10:14:17 +08:00
if self.headless:
self.open_if_not_url("about:blank")
print("\n This test is not for Headless Mode.")
self.skip('Do not use "--headless" with this test.')
self.open("https://google.com/ncr")
2022-06-25 02:14:17 +08:00
self.hide_elements("iframe")
self.assert_element('input[title="Search"]')
self.set_attribute('[action="/search"]', "action", "//bing.com/search")
self.set_attributes('[value="Google Search"]', "value", "Bing Search")
2021-09-29 15:21:35 +08:00
self.type('input[title="Search"]', "SeleniumBase GitHub Docs Install")
2021-05-19 02:31:07 +08:00
self.sleep(0.5)
self.js_click('[value="Bing Search"]')
2020-09-12 06:56:01 +08:00
self.highlight("h1.b_logo")
2022-05-21 11:18:44 +08:00
self.highlight_click('[href*="github.com/seleniumbase/SeleniumBase"]')
self.highlight_click('[href="/seleniumbase/SeleniumBase"]')
2021-10-06 05:33:07 +08:00
self.highlight_click('a[title="examples"]')
2021-01-24 15:51:00 +08:00
self.assert_text("examples", "strong.final-path")
2022-05-21 11:18:44 +08:00
self.highlight_click('a[title="test_hack_search.py"]')
2021-01-24 15:51:00 +08:00
self.assert_text("test_hack_search.py", "strong.final-path")
2022-05-21 11:18:44 +08:00
self.highlight("strong.final-path")