Good day!

As part of the task of remaking the Selenium script, there was a problem with replacing the x-path locator with a css locator . I would be grateful if someone more experienced will tell you how to get from xpath-locator of the form

xpath=//div/div[ @id ="mLoc"][a/@href="go.htm"] 

css locator That is, it is necessary to select all div elements with the id = "mLoc" attribute that have an embedded element a with the href = "go.htm" attribute, which are child elements of other div elements.

  • Thanks for the link, I carefully studied the material. It does not give an answer to the question "how to select an element with the help of a css-locator according to the attributes of nested (child) elements?", To which, in fact, I am looking for an answer. All these examples allow you to select only the attributes of the current elements (but not children!). - tenety
  • I’ve heard about Selenium for the first time, so I’ll not say for sure, but just try a different approach, for example, make a wrapper for class divs and repeat the “focus” - Gorets '15

1 answer 1

 css_locator = 'div div[id="mLoc"] a[href="go.htm"]' 

it seems so. 5 Selectors - here is a complete guide, perhaps your locator can be simplified.