1. 程式人生 > >python學習之sellinum簡單建立。

python學習之sellinum簡單建立。

首先進行了簡單的程式碼測試。 

#-*- encoding=utf-8 -*-
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.baidu.com")
browser.find_element_by_id("kw").send_keys("selenium")
browser.find_element_by_id("su").click()
browser.quit()

我們看一下這個模組的結構

然後開啟__init__.py會發現  

 

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

from .firefox.webdriver import WebDriver as Firefox  # noqa
from .firefox.firefox_profile import FirefoxProfile  # noqa
from .firefox.options import Options as FirefoxOptions  # noqa
from .chrome.webdriver import WebDriver as Chrome  # noqa
from .chrome.options import Options as ChromeOptions  # noqa
from .ie.webdriver import WebDriver as Ie  # noqa
from .ie.options import Options as IeOptions  # noqa
from .edge.webdriver import WebDriver as Edge  # noqa
from .opera.webdriver import WebDriver as Opera  # noqa
from .safari.webdriver import WebDriver as Safari  # noqa
from .blackberry.webdriver import WebDriver as BlackBerry  # noqa
from .phantomjs.webdriver import WebDriver as PhantomJS  # noqa
from .android.webdriver import WebDriver as Android  # noqa
from .webkitgtk.webdriver import WebDriver as WebKitGTK # noqa
from .webkitgtk.options import Options as WebKitGTKOptions # noqa
from .remote.webdriver import WebDriver as Remote  # noqa
from .common.desired_capabilities import DesiredCapabilities  # noqa
from .common.action_chains import ActionChains  # noqa
from .common.touch_actions import TouchActions  # noqa
from .common.proxy import Proxy  # noqa

__version__ = '3.14.1'

執行的是上面的倒入模組操作。

第一行程式碼 webbroswer模組下面有一些檔案webdriver子模組。

匯入模組不如說是路徑,如果不是檔案,那麼依然不能使用方法,到了檔案級別的才屬於宣告定義。

 然後我們在下面的一些檔案裡面可以看到我們上面使用的方法的定義。

比如 

    def find_element_by_id(self, id_):
        return self.find_element(by=By.ID, value=id_)

    def find_element_by_name(self, name):
        return self.find_element(by=By.NAME, value=name)

    def find_elements_by_name(self, name):
        return self.find_elements(by=By.NAME, value=name)

    def find_element_by_tag_name(self, name):
        return self.find_element(by=By.TAG_NAME, value=name)

    def find_elements_by_tag_name(self, name):
        return self.find_elements(by=By.TAG_NAME, value=name)

    def find_element_by_class_name(self, name):
        return self.find_element(by=By.CLASS_NAME, value=name)

    def find_elements_by_class_name(self, name):
        return self.find_elements(by=By.CLASS_NAME, value=name)

    def find_element_by_css_selector(self, css_selector):
        return self.find_element(by=By.CSS_SELECTOR, value=css_selector)

下面是方法

>>> from selenium import webdriver
>>> dir(webdriver.Chrome())

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', 
'__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'__weakref__', '_file_detector', '_is_remote', '_mobile', '_switch_to', '_unwrap_value', 
'_web_element_cls', '_wrap_value', 'add_cookie', 'application_cache', 'back', 
'capabilities', 'close', 'command_executor', 'create_options', 'create_web_element', 
'current_url', 'current_window_handle', 'delete_all_cookies', 'delete_cookie', 
'desired_capabilities', 'error_handler', 'execute', 'execute_async_script', 
'execute_cdp_cmd', 'execute_script', 'file_detector', 'file_detector_context', 
'find_element', 'find_element_by_class_name', 'find_element_by_css_selector', 
'find_element_by_id', 'find_element_by_link_text', 'find_element_by_name', 
'find_element_by_partial_link_text', 'find_element_by_tag_name', 'find_element_by_xpath', 
'find_elements', 'find_elements_by_class_name', 'find_elements_by_css_selector', 
'find_elements_by_id', 'find_elements_by_link_text', 'find_elements_by_name', 
'find_elements_by_partial_link_text', 'find_elements_by_tag_name', 
'find_elements_by_xpath', 'forward', 'fullscreen_window', 'get', 'get_cookie', 
'get_cookies', 'get_log', 'get_network_conditions', 'get_screenshot_as_base64', 
'get_screenshot_as_file', 'get_screenshot_as_png', 'get_window_position', 
'get_window_rect', 'get_window_size', 'implicitly_wait', 'launch_app', 'log_types', 
'maximize_window', 'minimize_window', 'mobile', 'name', 'orientation', 'page_source', 
'quit', 'refresh', 'save_screenshot', 'service', 'session_id', 'set_network_conditions', 
'set_page_load_timeout', 'set_script_timeout', 'set_window_position', 'set_window_rect', 
'set_window_size', 'start_client', 'start_session', 'stop_client', 'switch_to', 
'switch_to_active_element', 'switch_to_alert', 'switch_to_default_content', 
'switch_to_frame', 'switch_to_window', 'title', 'w3c', 'window_handles']