Do you have questions ? We got the answers!

Ask a question:

1
WARNING: WebDriverException thrown by findElement(By.xpath:

Open 1 Answers 38 Views

For the below code:
 

public class CommentTask {
    WebDriver driver;
    
    public CommentTask(WebDriver driver)
    {
        this.driver = driver;
    }
    

    public void commentOnTask()
    {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        try {
             
         wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("text_div")));
            
        }
        catch(org.openqa.selenium.TimeoutException e){
            System.out.println(e.getMessage());
                
        }
        
        driver.findElement(By.className("text_div")).sendKeys("Test Comment");
    WebElement submitButton =    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"comments-task-6-59ba23e91bb06\"]/div/div/div[3]/div[2]/form/button")));
    submitButton.click();
    

    }

}



Am able to enter text into the Comment field but unable to find the path of Submit button and click on it. getting below exception:
WARNING: WebDriverException thrown by findElement(By.xpath: //*[@id="comments-task-6-59ba23e91bb06"]/div/div/div[3]/div[2]/form/button)
org.openqa.selenium.WebDriverException: Failed to decode response from marionette.

Can you please help me with this

1Comments
commented Sep 14 by Priyanka91 (91 points)
Thanks. Please help me on this

1 Answer

0

It looks like your ID, 

comments-task-6-59ba23e91bb06

is dynamically generated. I suggest you use regular expression in your XPath expression.

Something as given below.

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"^comments-task*\"]/div/div/div[3]/div[2]/form/button")));

The above may not work as I just tried to give you an example. You can find regular expression by googling it out.

answered Sep 14 by SunilBhaskar (433 points)
3Comments
commented Sep 14 by Priyanka91 (91 points)
It worked with the below regular expression :
//*[contains(@id, 'comments-task')]/div/div/div[3]/div[2]/form/button

Thanks!
commented Sep 14 by SunilBhaskar (433 points)
Thank you for sharing your solution!
commented Sep 14 by SunilBhaskar (433 points)
I have created a new question related to your solution. It would be great if you can post your solution there.

https://softwaretestingboard.com/qna/2407/selenium-regular-expression-expression-starting-certain

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 433 pointsSunilBhaskar

    41 questions 15 answers32 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 364 pointssumitkumarwatts

    0 questions 14 answers0 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...