Selenium自動化之獲取元素的css屬性值

2021-09-25 23:25:42 字數 1228 閱讀 7477

#獲取搜尋輸入框的高度

searchbox.value_of_css_property(「height」)

#獲取搜尋輸入框的寬度

searchbox.value_of_css_property(「width」)

#獲取搜尋輸入框的字型

searchbox.value_of_css_property(「font-family」)

import unittest

import time

from selenium import webdriver

class visitsogoubyie(unittest.testcase):

def setup(self):

# 啟動ie瀏覽器

self.driver = webdriver.ie(executable_path="g:\\iedriverserver")

def test_getwebelementcssvalue(self):

url = ""

# 訪問baidu首頁

self.driver.get(url)

# 找到搜尋輸入框元素

searchbox = self.driver.find_element_by_id("kw")

# 使用頁面元素物件的value_of_css_property()方法獲取元素的css屬性值

print("搜尋輸入框的高度是:", searchbox.value_of_css_property("height"))

print("搜尋輸入框的寬度是:", searchbox.value_of_css_property("width"))

font = searchbox.value_of_css_property("font-family")

print("搜尋輸入框的字型是:", font)

# 斷言搜尋輸入框的字型是否是arial字型

self.assertequal(font, "arial")

def teardown(self):

# 退出ie瀏覽器

python自動化之selenium

一 環境 1 selenium 安裝 pip install selenium 版本號 後可省略,預設安裝最新版本 檢視 pip show selenium 解除安裝 pip uninstall selenium 2 瀏覽器驅動 以chrome為例 國內可訪問 windows 解壓後將驅動移動至ch...

Selenium自動化之操作cookies

操作cookies import unittest import time from selenium import webdriver from selenium.webdriver import actionchains class visitsogoubyie unittest.testcas...

初識selenium之web自動化

今天我們學習下如何使用python編寫web自動化,談到web自動化,那麼我們需要了解下市面上做web自動化的幾種方式,robotframework工具,網紅webui自動化測試神器 cypress,以及我們今天所要學習的selenium,為什麼使用selenium?上手快,開源免費,市面上使用率較...