0

Whatever companyCode I specify in the method it always chooses 3M Canada. Before it worked perfectly but after a few days it stopped even if I didn't do any changed in the code. The XPATH of the table also didn't change, because I've checked it. It should choose the 4007 companyCode.

  public void selectCompanyCodeFromTable(String companyCode) throws InterruptedException {

    Thread.sleep(5000);
    List<WebElement> rows = shoppingCart.companyCodeTable.findElements(By.tagName("tr"));
    for (WebElement row : rows) {
        List<WebElement> cells = row.findElements(By.tagName("td"));
        for(WebElement cell : cells){
            if (cell.getText().equalsIgnoreCase(companyCode)) {
                cell.click();
                log.info("The company has been selected");
            }
        }

    }
}

the method used in the test:

@Test(priority = 1, description = "Shopping Cart Creation")
    public void test01() throws InterruptedException {

//other methods till this one:

  shoppingCart.selectCompanyCodeFromTable("4007");
}

enter image description here

3
  • 1
    try to print get Text before equating so you know is happening – PDHide Nov 12 '20 at 14:24
  • When I print the value, I get also 4007 value so don't understand why it doesn't click it. – Beti Nov 12 '20 at 15:16
  • print the outerHTML attribute and see if you are getting the actual element you expect cell.getAttribute('outerHTML') , there may be multiple cells with same text in the DOM with display off . You might have to use more attribute like id or class to pin point the element – PDHide Nov 12 '20 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.