Selenium WebDriver: clicking a visible button inside a row of a table

dannydvo10

My apology as this question is quite long.

To be more specific, I am trying to click on the Pencil icon (Edit button) that is shown on the 4th row

enter image description here

Here's the code I tried to execute:

WebElement ele = driver.findElement(By.xpath("//a[contains(@title, 'Edit Row')]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
Executor1.executeScript("arguments[0].click();", ele);

And here's the HTML code enter image description here

After I ran the selenium code, the driver actually clicked on the Edit button of the 1st row (Administration | NA) instead of the 4th. I found out that not only the 1st but other rows also have the same HTML code, only difference was that the Pencil/Edit button is hidden because I wasn't the one that created the values of that row.

I did try with the following code as well:

driver.findElement(By.xpath("//a[contains(@title, 'Edit Row')]")).click();

I then received the error

element is not currently visible and so may not be interacted with

It seems the driver was still looking at the hidden Edit button in the first row, instead of the obvious visible one in 4th.

Is there anyway that I could click on the Edit button based on the value instead of the row number? The reason is that in the future, the value I enter for testing may not end up in 4th but 1st or 10th row.

Last but not least, my Safari can't seem to run the JS Executor code, everytime I gave it a go, the following error returned:

org.openqa.selenium.WebDriverException: 'undefined' is not a function (WARNING: The server did not provide any stacktrace information)

Can someone shed some light on this for me as well?

Cheers

dannydvo10

Thanks murali and JeffC for the suggestions, I have managed to get the driver to click on the displayed Pencil with this:

List<WebElement> EditButtons = driver.findElements(By.cssSelector("a[title='Edit Row']"));

        for(WebElement button : EditButtons) {
         if(button.isDisplayed()) {
             button.click();
          }
        }

Although it only solved half of the issue, I am trying to click on the displayed Edit button based on the value next to it. If I create another row with the value of 'Test234' and if the row is placed under the 4th row, the Edit button of 'Test234' won't be clicked. Any suggestion? I tried this but it doesn't seem to work, driver still clicked on the first visible edit button it saw:

List<WebElement> EditButtons = driver.findElements(By.cssSelector("a[title='Edit Row']"));
String textvalue = driver.findElement(By.xpath("//span[contains(text(),'test456')]")).getText();

        for(WebElement button : EditButtons) {
         if(button.isDisplayed() && textvalue.equalsIgnoreCase("test456")) {
             button.click();
          }
        }

UPDATE: Alright, issue resolved, I switched back to use xpath instead of cssSelector, then modified Vagnesh's suggestion (Thanks Vagnesh !!) a bit and now the driver is clicking on the visible edit button next to the text I search for without going through the loop

driver.findElement(By.xpath("//span[contains(text(), 'Enter my desired Text here')]/following::div//a[contains(@title,'Edit Row')]")).click();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get table cell text based on target row with Selenium Webdriver

From Dev

Selenium Webdriver: Element is not currently visible

From Dev

Parse HTML table after clicking a button to make it visible

From Dev

Button inside table row tr, when clicking button only do button action

From Dev

Get the model when clicking a button on a table row

From Dev

Selenium Java Click Radio Button That is in a Table Row

From Dev

selenium webdriver to get visible row number in table

From Dev

Selenium Webdriver: Element Not Visible Exception

From Dev

How to find the table row number using Selenium Webdriver Java

From Dev

Button not visible in Html table?

From Dev

StaleElementReferenceException occurs when clicking on the buttons of a changed table (Python > Selenium Webdriver)

From Dev

Delete mysql Table row by clicking submit button php

From Dev

Get row id of a table row after selecting a row and clicking the button in datatables

From Dev

Selenium Webdriver - Element not visible

From Dev

Clicking a button which is inside another element Selenium

From Dev

Clicking on a button in selenium

From Dev

Selenium webdriver - clicking on checkbox based on table value

From Dev

Parse HTML table after clicking a button to make it visible

From Dev

Button inside table row tr, when clicking button only do button action

From Dev

Get the model when clicking a button on a table row

From Dev

selenium webdriver to get visible row number in table

From Dev

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

From Dev

Clicking First Visible Element of a Certain Class in Selenium

From Dev

How to delete row of table with a button inside

From Dev

Element not visible in selenium webdriver

From Dev

how to remove the row of the table containing textbox by clicking the respective remove button

From Dev

Selenium webdriver -keep clicking on next button of calendar until the month title match found using java

From Dev

Show table by clicking a button

From Dev

clicking a button inside table view

Related Related

  1. 1

    How to get table cell text based on target row with Selenium Webdriver

  2. 2

    Selenium Webdriver: Element is not currently visible

  3. 3

    Parse HTML table after clicking a button to make it visible

  4. 4

    Button inside table row tr, when clicking button only do button action

  5. 5

    Get the model when clicking a button on a table row

  6. 6

    Selenium Java Click Radio Button That is in a Table Row

  7. 7

    selenium webdriver to get visible row number in table

  8. 8

    Selenium Webdriver: Element Not Visible Exception

  9. 9

    How to find the table row number using Selenium Webdriver Java

  10. 10

    Button not visible in Html table?

  11. 11

    StaleElementReferenceException occurs when clicking on the buttons of a changed table (Python > Selenium Webdriver)

  12. 12

    Delete mysql Table row by clicking submit button php

  13. 13

    Get row id of a table row after selecting a row and clicking the button in datatables

  14. 14

    Selenium Webdriver - Element not visible

  15. 15

    Clicking a button which is inside another element Selenium

  16. 16

    Clicking on a button in selenium

  17. 17

    Selenium webdriver - clicking on checkbox based on table value

  18. 18

    Parse HTML table after clicking a button to make it visible

  19. 19

    Button inside table row tr, when clicking button only do button action

  20. 20

    Get the model when clicking a button on a table row

  21. 21

    selenium webdriver to get visible row number in table

  22. 22

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

  23. 23

    Clicking First Visible Element of a Certain Class in Selenium

  24. 24

    How to delete row of table with a button inside

  25. 25

    Element not visible in selenium webdriver

  26. 26

    how to remove the row of the table containing textbox by clicking the respective remove button

  27. 27

    Selenium webdriver -keep clicking on next button of calendar until the month title match found using java

  28. 28

    Show table by clicking a button

  29. 29

    clicking a button inside table view

HotTag

Archive