Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/common/results_page.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
19
from selenium.webdriver.common.by import By
20
21
22
class ResultsPage:
23
"""This class models a google search result page."""
24
25
def __init__(self, driver):
26
self._driver = driver
27
28
def is_loaded(self):
29
return "/search" in self._driver.get_current_url()
30
31
def load(self):
32
raise Exception("This page shouldn't be loaded directly")
33
34
def link_contains_match_for(self, term):
35
result_section = self._driver.find_element(By.ID, "res")
36
elements = result_section.find_elements(By.XPATH, ".//*[@class='l']")
37
for e in elements:
38
if term in e.get_text():
39
return True
40
return False
41
42