Most people are using selenium When positioning elements , It's using xpath location , because xpath It can basically solve the needs of positioning .css Positioning is often overlooked , Actually css Positioning also has its value ,css Faster positioning , The grammar is more concise .
This article css Positioning method of , It's mainly a comparison with the last one xpath To the , Basically xpath It can be done ,css It can also be done . Two comparative studies , Easier to understand .

One 、css: Attribute positioning

1.css It's possible to do this through the id、class、 The three general attributes of tags are directly located at

2. Here is the baidu input box html Code :

<input id="kw" class="s_ipt" type="text" autocomplete="off" maxlength="100" name="wd"/>

3.css use # The sign means id attribute , Such as :#kw

4.css use . Express class attribute , Such as :.s_ipt

5.css Just use the label name , No identifier , Such as :input

Two 、css: Other attributes

1.css In addition to being able to label 、class、id These three general attributes are located outside , It can also be located by other attributes

2. Here's the format for locating other properties

3、 ... and 、css: label

1.css A page can locate elements through a combination of tags and attributes

Four 、css: Hierarchy

1. In the previous article xpath We talk about the positioning of hierarchical relations , here css The same effect can be achieved

2. Such as xpath://form[@id='form']/span/input and

//form[@class='fm']/span/input It can also be used. css Realization

5、 ... and 、css: Indexes

1. The following is an example , Just like the last one

2.css It can also be indexed option:nth-child(1) To locate the subelements , With this xpath There's a big difference in the way it's written , It's easy to understand , Directly translated is the number of children

 
 
6、 ... and 、css: Logical operations

1.css Logic operation can also be realized , Match two properties at the same time , Here with xpath Dissimilarity , No need to write and keyword

Selenium CSS More articles on positioning grammar

  1. Selenium2+python automation -CSS Positioning grammar

    Preface Some people are using selenium When positioning elements , It's using xpath location , because xpath It can basically solve the needs of positioning .css Positioning is often overlooked , Actually css Positioning also has its value ,css Faster positioning , The grammar is more concise . This article css Of ...

  2. selenium - css location

    Preface : CSS(Cascading Style Sheets) It's a language , It's used to describe HTML and XML The presentation of the document . CSS Use selectors to bind properties to page elements . These selectors can be selenium ...

  3. Exercises --- Write 5 Kind of css Positioning grammar

    Write at least 5 Kind of css grammar ( Every grammar is different )

  4. selenium css Positioning mode

  5. selenium Use Xpath+CSS+JavaScript+jQuery Positioning method of ( Treatment selenium All kinds of positioning cannot be found , Complications that can't be clicked )

    Tell you , You always rely on that firebug,chrome Of F12 Right click to copy xpath Absolutely one day, you will not be able to locate your life and death by stepping on the land mine , At this time, we need to learn to write by ourselves xpath, The brain is always smarter than the computer , Start putting xpath Give me the grammar ...

  6. python selenium And CSS location

    ccs The advantages of :css relative xpath Grammar than xpath concise , Positioning speed ratio xpath fast css The shortcomings of :css Logical operators are not supported to locate , and xpath Support .css There are various forms of location grammar , relative xpath It's hard to remember . css ...

  7. UI automated testing ( Two ) Browser operation and location of elements (xpath Positioning and css Location details )

    Selenium Under the Webdriver Tool support FireFox(geckodriver). IE(InternetExplorerDriver).Chrome(ChromeDriver). Opera( ...

  8. selenium Various positioning methods ( turn )

    selenium Use Xpath CSS JavaScript jQuery Positioning method of ( Treatment selenium All kinds of positioning cannot be found , Complications that can't be clicked ) 2017 year 07 month 28 Japan 22:47:36 Read the number :369 ...

  9. selenium And css Positioning summary

    Preface Most people are using selenium When positioning elements , It's using xpath location , because xpath It can basically solve the needs of positioning .css Positioning is often overlooked , Actually css Positioning also has its value ,css Faster positioning , The grammar is more concise . This article css ...

Random recommendation

  1. Bootstap datetimepicker Report errors TypeError: intermediate value

    Bootstrap datetimepicker There are multiple versions , In the official link , It's just datepicker, There is no choice of time , The original datetimepicker No more updates , You can't use the new version of jquery. Now? http ...

  2. 【USACO 2.1】Healthy Holsteins

    /* TASK: holstein LANG: C++ URL: http://train.usaco.org/usacoprob2?a=SgkbOSkonr2&S=holstein SOLV ...

  3. zepto Touch event resolution

    Mobile project development process , We often need to use sliding events to deal with some effects . Usually , We will pass  touchstart->touchmove->touchend   To define this event . The trigger of these events is ...

  4. ArcGis Implementation add MultiLayerMarkerSymbol( Multiple symbols are superimposed to generate new symbols )

    , , );             pMarkerSymbol.Angle = ;             pMarkerSymbol.XOffset = ;;;;, , );            ...

  5. be based on NPOI Of Execl Import and export examples

    source address :http://bbs.csdn.net/topics/390830774

  6. Send automatically EMAIL

    *&---------------------------------------------------------------------* *& Report  ZPP_SEND ...

  7. js add to enter event

    $(function () { document.onkeydown = function (e) { var ev = document.all ? window.event : e; ) { if ...

  8. 【 turn 】#include,#import,@class The difference between

    #include         #include  <>    : For references to system files , The compiler will look up the file in the system file directory .           #include "xx.h ...

  9. linux Medium &amp;&amp; and ||(linux in = and == The effect is the same )

    1. command 1 && command 2 command 1 The successful execution is in the execution of the command 2 2. command 1 || command 2 command 1 After the execution fails, execute the command 2 I think it's all judgment .

  10. Activt The function of workflow database corresponding table

    1. Resource pool process rule table 1)       act_re_deployment Deployment information sheet 2)       act_re_model                Process design model deployment table 3)       ...