Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/
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
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.
This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!
1.4k questions
1.6k answers
866 comments
1.9k users