久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 香蕉av在线 | 一级黄色片免费观看 | 欧美日韩国产在线观看 | 中文字幕在线资源 | 日韩精品 | 国产中文在线 | 欧美国产精品 | av网站免费在线观看 | 黄色一级大片 | 中文字幕影院 | 性视频网 | 九九九精品视频 | 精品国产伦一区二区三区 | 在线免费看黄色 | 久久久久国产 | 亚洲欧美日韩成人 | 亚洲免费福利视频 | 99中文字幕 | 日韩欧美小视频 | 又黄又爽又色视频 | 性大毛片视频 | 五月婷综合| 亚洲天堂男人天堂 | 免费成人在线观看 | 欧美亚洲国产精品 | 五月婷婷激情 | 国产日韩免费 | 一区二区不卡视频 | 日韩精品在线观看视频 | 国产精品伦理一区 | 欧美成人精品一区二区三区在线看 | 欧美日韩激情 | 日韩欧美精品一区二区 | 精品黄色片| 激情小说五月天 | 久久av中文字幕 | 成人做爰www看视频软件 | 日韩精品在线免费观看 | 在线中文字幕av | 久久久久久国产精品 | 日韩一区二区三区视频 |