Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/common/google_one_box.py
1865 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
from page_loader import require_loaded
19
from results_page import ResultsPage
20
21
from selenium.common.exceptions import NoSuchElementException
22
from selenium.webdriver.common.by import By
23
24
25
class GoogleOneBox:
26
"""This class models a page that has a google search bar."""
27
28
def __init__(self, driver, url):
29
self._driver = driver
30
self._url = url
31
32
def is_loaded(self):
33
try:
34
self._driver.find_elemen(By.NAME, "q")
35
return True
36
except NoSuchElementException:
37
return False
38
39
def load(self):
40
self._driver.get(self._url)
41
42
@require_loaded
43
def search_for(self, search_term):
44
element = self._driver.find_element(By.NAME, "q")
45
element.send_keys(search_term)
46
element.submit()
47
return ResultsPage(self._driver)
48
49