Python教程

python+selenium+PageObject

本文主要是介绍python+selenium+PageObject,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import time

from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By


class HomePage:
    login_phone = (By.XPATH, '//form/div[1]/div/div/div/div/input')
    login_pwd = (By.XPATH, '//input[@placeholder="请输入密码"]')
    login_bt = (By.XPATH, '//form/div[4]/div/div[1]/div/button')

    def __init__(self, driver: WebDriver):
        self.driver = driver


    def input_phone(self,phone):
        self.driver.find_element(*self.login_phone).send_keys(phone)

    def input_pwd(self,passwd):
        self.driver.find_element(*self.login_pwd).send_keys(passwd)

    def input_bt(self):
        self.driver.find_element(*self.login_bt).click()



class BaoBeiPage:
    ordermang=(By.XPATH, '//*[@id="siderbar"]/div[1]/div/ul/div[3]/li/div/i[1]')
    baobeilist=(By.XPATH, '//a[text()="列表"]')

    def __init__(self, driver: WebDriver):
        self.driver = driver

    def enter_baobeilist(self):
        time.sleep(20)
        self.driver.find_element(*self.Ordermang).click()
        self.driver.find_element(*self.baobeilist).click()

driver=webdriver.Chrome()
page=HomePage(driver)
page.driver.get('http://www.baidu.com')
page.input_phone('11111111111')
page.input_pwd('654321')
page.input_bt()

这篇关于python+selenium+PageObject的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!