简体   繁体   English

解码 CssSelector 语句

[英]Decoding CssSelector Statements

I'm getting this error:我收到此错误:

unable to locate element: {"methode":"css selector","selector":".ftMtypSt-Primary> span"}

Code is being generated by the FireFox Developer Selenium IDE and exported to Python.代码正在由 FireFox 开发人员 Selenium IDE 生成并导出到 ZA7F5F35426B627411FC9231B。

driver.find_element(By.CSS_SELECTOR, ".ftMs-input").send_keys("Dan")
driver.find_element(By.CSS_SELECTOR, ".ftMtypSt-Primary > span").click()
driver.find_element(By.CSS_SELECTOR, "li:nth-child(4) > div").click()

I want to be able to decode these parts of the statements: .ftMs-input , .ftMtypSt-Primary > span and li:nth-child(4) > div我希望能够解码语句的这些部分: .ftMs-input.ftMtypSt-Primary > spanli:nth-child(4) > div

The can be decoded as follows: 可以解码如下:

  • .ftMs-input : Within a cssSelector . .ftMs-input :在 cssSelector . indicates classname .表示类名 So .ftMs-input would search for an element with classname as ftMs-input .因此.ftMs-input将搜索名为ftMs-input的元素。 As an example:举个例子:

     <input class="ftMs-input"...>
  • .ftMtypSt-Primary > span : Similarly .ftMtypSt-Primary would search for an element with classname as ftMtypSt-Primary , > indicates immediate descendant, which is a <span> tag. .ftMtypSt-Primary > span :类似地.ftMtypSt-Primary会搜索名为ftMtypSt-Primary的元素, >表示直接后代,即<span>标签。 As an example:举个例子:

     <button class="ftMtypSt-Primary"...> <span>...</span>
  • li:nth-child(4) > div : Similarly li:nth-child(4) would select every <li> element that is the forth child of its parent, > indicates immediate descendant, which is a <div> tag. li:nth-child(4) > div :类似地li:nth-child(4)将 select 每个<li>元素是其父元素的第四个子元素, >表示直接后代,这是一个<div>标签。 As an example:举个例子:

     <ul class="list items"...> <li>...</li> <li>...</li> <li>...</li> <li> <div>This node would be selected</div> </li>

tl; tl; dr博士

CSS Selector Reference CSS 选择器参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM