Get the App
SLTechnology News&Howtos  ›  Servers  › 

How selenium grabs elements and excludes a particular class tag

Shulou Source: shulou.com Published: 2022-05-31 18:17:39 10月02日 Update

Editor to share with you how selenium grabs elements to exclude a specific class tag, I hope you will learn something after reading this article, let's discuss it together!

Excluding a certain factor, the first priority is to think of regular expressions, but it does not succeed for a long time. It feels like selenium is operating on the element's attrs by pressing re search, and $is useless for string end detection.

BeautifulSoup can be detected with the class of the element ['class'] output element, but the BeautifulSoup object can no longer click and does not meet expectations. Selenium does not have such a syntax, so choose through xpath:

ItemList = driver.find_elements_by_xpath ('/ / div [@ id = "choose-color"] / / div [@ class = "dd"] / / div [not (contains (@ class, "disabled"))]')

Stackoverflow has a reference: http://stackoverflow.com/questions/11024080/how-to-use-not-contains-in-xpath

Supplementary xpath usage:

Xpath=xpathExpression: Locate an element using an XPath expression. Xpath=//img [@ alt='The image alt text'] xpath=//table [@ id='table1'] / / tr [4] / td [2] xpath=//a [contains (@ href,'#id1')] xpath=//a [contains (@ href) '# id1')] / @ class xpath= (/ / table [@ class='stylee']) / / th [text () =' theHeaderText'] /.. / td xpath=//input [@ name='name2' and @ value='yes'] xpath=//* [text () = "right"] has finished reading this article I believe you have a certain understanding of "how selenium crawls elements to exclude a specific class tag". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Elements tags articles tests success nothing factors characters strings done objects feelings helplessness more endings regularities knowledge industry expressions grammar Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Redmi Apple vpn