Selecting row from filtered grid not working in Selenium

Viewed 45

I've been struggling with this situation for a long time. I'm using a MAGENTO 2 website (it is a multi language page).

I'm using SELENIUM & JAVA with chromedriver

I am trying to create an automation in a webpage, i have to enter a specific value in a dinamic table and after performing a "ENTER" event it is necessary to select the first row shown:

This is the table:

enter image description here

Take a look at this .gif

enter image description here


I should be able to click on any row after after applying a filter:

enter image description here

Note: That's where my program is not working, it wont click on the filtered row.

My automation is not able to click on the row within the label name "linea":

This is my automation working so far:

enter image description here

This is my code:

package first;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Script_codes {
    public static void main(String[] args){
    System.setProperty("webdriver.chrome.driver","C:\\Users\\Steve\\Desktop\\Me\\chromedriver.exe");

    WebDriver driver = new ChromeDriver();
    driver.get("https://stage.nbm2.test/backend");
    driver.findElement(By.id("username")).sendKeys("test");
    driver.findElement(By.id("login")).sendKeys("test");
    driver.findElement(By.xpath("//*[@id=\"login-form\"]/fieldset/div[3]/div[2]/button")).click();
    driver.findElement(By.xpath("//*[@id=\"menu-magento-backend-stores\"]/a")).click();
    driver.findElement(By.xpath("//*[@id=\"menu-magento-backend-stores\"]/div/ul/li[2]/ul/li[2]/div/ul/li[3]/a")).click();
    driver.findElement(By.xpath("//*[@id=\"attributeGrid_filter_frontend_label\"]")).sendKeys("linea");
    driver.findElement(By.xpath("//*[@id=\"attributeGrid_filter_frontend_label\"]")).sendKeys(Keys.ENTER);
    driver.findElement(By.className("col-label col-frontend_label")).click();
    
    }
}

How can i solve this? am i doing anything wrong?

1 Answers

I was able to solve this: I used:

driver.findElement(By.xpath("//*[@id=\"attributeGrid_table\"]/tbody/tr/td[1]")).click();

instead of:

driver.findElement(By.className("col-label col-frontend_label")).click();

Thank you all!

Related