久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在使用 Selenium Python 之前定位偽元素 ::befor

How locate the pseudo-element ::before using Selenium Python(如何在使用 Selenium Python 之前定位偽元素 ::before)
本文介紹了如何在使用 Selenium Python 之前定位偽元素 ::before的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 Selenium Python 來定位標簽元素.我想使用 ::before 來定位它,因為這是一個彈出窗口.

 <div class="crow" grp="0" grpname="Pizza Size">::前<標簽類="label0" cid="1"><input type="radio" name="0" coname="M" sname="" price="9.99" value="392">M<b class="ip">9.99</b></標簽><label class="label0" cid="1"><input type="radio" name="0" coname="L" sname="" price="11.99" value="393">L<b class="ip">11.99</b></label><div style="clear:both"></div></div>

我不知道如何使用 ::before 來定位它,有朋友可以幫忙嗎?

解決方案

  • 代碼塊:

    從 selenium 導入 webdriver選項 = webdriver.ChromeOptions()options.add_argument("開始最大化")options.add_experimental_option("excludeSwitches", ["enable-automation"])options.add_experimental_option('useAutomationExtension', False)driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')driver.get('https://meyerweb.com/eric/css/tests/pseudos-inspector-test.html')script = "返回 window.getComputedStyle(document.querySelector('body>p.el'),':after').getPropertyValue('content')"打印(driver.execute_script(腳本).strip())

  • 控制臺輸出:

    " (fin.)"

此控制臺輸出與 ::aftercontent 屬性的 value 完全匹配

<小時>

這個用例

要提取 ::before 元素的 content 屬性的值,您可以使用以下解決方案:

script = "return window.getComputedStyle(document.querySelector('div.crow'),':before').getPropertyValue('content')"打印(driver.execute_script(腳本).strip())

<小時>

結尾

一些相關文件:

  • Document.querySelector()
  • Window.getComputedStyle()

I'm using Selenium Python to locate label element.I want to use ::before to locate it,because this is a pop window.

 <div class="crow" grp="0" grpname="Pizza Size">
    ::before
    <label class="label0" cid="1">
    <input type="radio" name="0" coname="M" sname="" price="9.99" value="392">M<b class="ip">9.99</b>
    </label>
    <label class="label0" cid="1"><input type="radio" name="0" coname="L" sname="" price="11.99" value="393">L<b class="ip">11.99</b>
    </label><div style="clear:both">
    </div>
    </div>

I have no idea how to use ::before to locate it,any friend can help?

解決方案

Pseudo Elements

A CSS pseudo-element is used to style specified parts of an element. It can be used to:

  • Style the first letter, or line, of an element
  • Insert content before, or after, the content of an element

::after

::after is a pseudo element which allows you to insert content onto a page from CSS (without it needing to be in the HTML). While the end result is not actually in the DOM, it appears on the page as if it is, and would essentially be like this:

CSS:

div::after {
  content: "hi";
}


::before

::before is exactly the same only it inserts the content before any other content in the HTML instead of after. The only reasons to use one over the other are:

  • You want the generated content to come before the element content, positionally.
  • The ::after content is also "after" in source-order, so it will position on top of ::before if stacked on top of each other naturally.

Demonstration of extracting properties of pseudo-element

As per the discussion above you can't locate the ::before element within the DOM Tree but you can always be able to retrieve the contents of the pseudo-elements, i.e. ::before and ::after elements. Here's an example:

To demonstrate, we will be extracting the content of ::after element (snapshot below) within this website:

  • Code Block:

    from selenium import webdriver
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')
    driver.get('https://meyerweb.com/eric/css/tests/pseudos-inspector-test.html')
    script = "return window.getComputedStyle(document.querySelector('body>p.el'),':after').getPropertyValue('content')"
    print(driver.execute_script(script).strip())
    

  • Console Output:

    " (fin.)"
    

This console output exactly matches the value of the content property of the ::after element as seen in the HTML DOM:


This usecase

To extract the value of the content property of the ::before element you can use the following solution:

script = "return window.getComputedStyle(document.querySelector('div.crow'),':before').getPropertyValue('content')"
print(driver.execute_script(script).strip())


Outro

A couple of relevant documentations:

  • Document.querySelector()
  • Window.getComputedStyle()

這篇關于如何在使用 Selenium Python 之前定位偽元素 ::before的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 黑人精品欧美一区二区蜜桃 | 视频1区2区 | 在线播放中文字幕 | 欧美一级在线观看 | 色综合桃花网 | 自拍 亚洲 欧美 老师 丝袜 | 夜夜艹天天干 | 成人精品免费 | av资源网站 | 一a级片 | 天天舔天天 | 亚洲精品大全 | 免费一区二区三区 | 天天天操天天天干 | 9porny九色视频自拍 | 九九亚洲 | 毛片国产 | 亚洲精品一区二区网址 | 成人一区二区三区在线观看 | 一级女毛片 | 日韩在线视频观看 | 久久高清免费视频 | 亚洲视频免费 | 亚洲性人人天天夜夜摸 | 日韩综合在线播放 | 国产精品视频不卡 | 久久精品视频在线播放 | 亚洲精品一区在线观看 | 一级毛片免费看 | 国产精品一区二区三区在线 | 亚洲高清在线观看 | 一区二区三区四区在线 | 91偷拍精品一区二区三区 | 91啪亚洲精品 | 国产精品日韩高清伦字幕搜索 | 久久久xxx | 精品无码久久久久久国产 | 久久久久久久综合色一本 | 嫩草视频在线免费观看 | 国产精品久久av | 999精品视频 |