WebDriver Selenium: Need to select element in the table after some element

Eliyahu

The HTML page contains a table of users details.
I need to remove user.
I can select the first element in the row by username.
I need to select the "Delete" button on that row to delete that user.
The HTML structure is:

<table id="tblUsersGrid" cellpadding="2">  
<thead>  
<tbody>
<tr class="aboutMeRow" data-parentid="223">  
<tr>  
<tr>  
 ...
<tr>
    <td class="cell cell_278 cell_NameCell">xoxo</td>
    <td class="optionIcon overrideFloat orgIcon cell cell_278 gridCell"></td>  
    <td class="cell cell_278 gridCell">Custom</td>  
    <td class="cell cell_278 gridCell">qaadmin</td>  
    <td class="cell cell_278 gridCell">0</td>  
    <td class="cell gridCell">  
        <div class="removeAccountIcon"></div>  
    <td class="cell gridCell">  
        <div class="editAccountIcon"></div>  
    </td>  
    <td></td>  
</tr>  

So I can easily select the desired row by

driver.findElement(By.xpath("//td[@class='cell_NameCell'][contains(text(),'xoxo')]"))  

But how can I reach the removeAccountIcon element on that row?
I saw many questions dealing with selecting elements inside tables but didn't find solution for this issue.
Is there a way to do this by CSS selector, not only by Xpath? (I am sure there is a Xpath solution for this).

Abhishek Yadav

Xpath axes preceding-sibling would helps you to resolve the issue. You can try below xpath:

//td[preceding-sibling::td[contains(text(),'xoxo')]][5]/div[@class='removeAccountIcon']

Let me know if it works for you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selenium - select an element in a table after another element

From Dev

Selenium Webdriver, can not select element

From Dev

Selenium, Java. Need to select ancestor element inside table by Xpath

From Dev

Select an element by the text it contains with Selenium Webdriver

From Dev

Selenium WebDriver - If element present select it, if not ignore it and continue to next element

From Dev

Selenium WebDriver - If element present select it, if not ignore it and continue to next element

From Dev

Selenium Webdriver element identification

From Dev

Selenium WebDriver element traverse

From Dev

Selenium Webdriver - Element not visible

From Dev

Disabling an element in selenium webdriver

From Dev

Element not visible in selenium webdriver

From Dev

how to select element in multi select box in selenium webdriver

From Dev

how to select element in multi select box in selenium webdriver

From Dev

Set value for every select element - Java Selenium WebDriver

From Dev

How to select a web element by text with Selenium WebDriver, Java

From Dev

How to randomly select and click on element with selenium webdriver (Python)?

From Dev

Select nested element by text using cssSelector - Selenium WebDriver

From Dev

Selenium Webdriver - Unable to find element after page refresh/redirect

From Dev

Selenium Webdriver - Unable to find element after page refresh/redirect

From Dev

How to use Selenium Webdriver to locate particular element in table

From Dev

How to find specific table element with selenium webdriver in java?

From Dev

How to get span element into table row (Selenium Webdriver)

From Dev

Selenium webdriver: How to use getText on element in table which contains attribute

From Dev

"Element not found in the cache" in Selenium WebDriver

From Dev

Selenium Webdriver: Element is not currently visible

From Dev

How to scroll to element with Selenium WebDriver

From Dev

How to gettext() of an element in Selenium Webdriver

From Dev

Selenium WebDriver cannot find element

From Dev

Selenium Webdriver: Element Not Visible Exception

Related Related

  1. 1

    Selenium - select an element in a table after another element

  2. 2

    Selenium Webdriver, can not select element

  3. 3

    Selenium, Java. Need to select ancestor element inside table by Xpath

  4. 4

    Select an element by the text it contains with Selenium Webdriver

  5. 5

    Selenium WebDriver - If element present select it, if not ignore it and continue to next element

  6. 6

    Selenium WebDriver - If element present select it, if not ignore it and continue to next element

  7. 7

    Selenium Webdriver element identification

  8. 8

    Selenium WebDriver element traverse

  9. 9

    Selenium Webdriver - Element not visible

  10. 10

    Disabling an element in selenium webdriver

  11. 11

    Element not visible in selenium webdriver

  12. 12

    how to select element in multi select box in selenium webdriver

  13. 13

    how to select element in multi select box in selenium webdriver

  14. 14

    Set value for every select element - Java Selenium WebDriver

  15. 15

    How to select a web element by text with Selenium WebDriver, Java

  16. 16

    How to randomly select and click on element with selenium webdriver (Python)?

  17. 17

    Select nested element by text using cssSelector - Selenium WebDriver

  18. 18

    Selenium Webdriver - Unable to find element after page refresh/redirect

  19. 19

    Selenium Webdriver - Unable to find element after page refresh/redirect

  20. 20

    How to use Selenium Webdriver to locate particular element in table

  21. 21

    How to find specific table element with selenium webdriver in java?

  22. 22

    How to get span element into table row (Selenium Webdriver)

  23. 23

    Selenium webdriver: How to use getText on element in table which contains attribute

  24. 24

    "Element not found in the cache" in Selenium WebDriver

  25. 25

    Selenium Webdriver: Element is not currently visible

  26. 26

    How to scroll to element with Selenium WebDriver

  27. 27

    How to gettext() of an element in Selenium Webdriver

  28. 28

    Selenium WebDriver cannot find element

  29. 29

    Selenium Webdriver: Element Not Visible Exception

HotTag

Archive