python+selenium selenium.webdriver.common.by之By


By是selenium中內置的一個class,在這個class中有各種方法來定位元素

 

By所支持的定位器的分類:

CLASS_NAME = 'class name'
CSS_SELECTOR = 'css selector'
ID = 'id'
LINK_TEXT = 'link text'
NAME = 'name'
PARTIAL_LINK_TEXT = 'partial link text'
TAG_NAME = 'tag name'
XPATH = 'xpath'

 

用法

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

class LoginPage(Page):
    '''
    126郵箱登錄頁面模型
    '''

    url='/'


    username_loc=(By.ID, "idInput")
    password_loc=(By.ID, "pwdInput")
    submit_loc=(By.ID, "loginBtn")

    def type_username(self,username):
        self.find_element(*self.username_loc).send_keys(username)

    def type_password(self,password):
        self.find_element(*self.password_loc).send_keys(password)

    def submit(self):
        self.find_element(*self.submit_loc).click()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM