简体   繁体   中英

locate an element on selenium ide

Hello i am new for selenium IDE and i have a question about how to locate an specific element using selenium IDE.

I have HTML like following:

<div id="locator">
 <table class = "table-1">
 </table>
 <div class="something else">
 </div>
 <table class = "table-1">
  <tbody>
   <tr>
    <th>...</th>
    <td>
     <div class="adder">....</div>
    </td>
   </tr>
 </table>
</div>

The problem is that i want to locate the div element in the second table element Could anyone figure me out how to do that? Thanks in advance.

use the pseudo class :nth-of-type :

driver.FindElement(By.CssSelector("table.table-1:nth-of-type(2) > tbody > tr > td > div.adder"));

If you use the Selenium IDE, then use

css=table.table-1:nth-of-type(2) > tbody > tr > td > div.adder

See the Selenium IDE documentation .

Of course you could also use XPath instead of css ( http://docs.seleniumhq.org/docs/02_selenium_ide.jsp#locating-by-xpath ).

the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after)

Try this....

driver.FindElement(By.CssSelector("div#locator table:nth-of-type(2) div.adder"));

I know this is old, but the selector mentioned above is wrong. CSS doesn't support some pseudo-classes and pseudo-elements. The unsupported ones are listed below.

css=table.table-1:nth-child(2) > tbody > tr > td > div.adder

6.7. CSS

The CSS locator strategy uses CSS selectors to find the elements in the page. Selenium supports CSS 1 through 3 selectors syntax excepted CSS3 namespaces and the following:

pseudo-classes       pseudo-elements

:nth-of-type          ::first-line

:nth-last-of-type     ::first-letter

:first-of-type        ::selection

:last-of-type         ::before

:only-of-type         ::after

:visited    

:hover

:active

:focus

:indeterminate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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