При заходе на сайт не всегда может найти элемент на сайте. Поставил все возможные паузы, элемент на сайте всегда присутствует, но вот ошибка бывает, раз в 5 раз, а причину найти не могу
private void sendKomment(String saitKomment, String text)throws Exception {
entrance(saitKomment); //Это переход на сайт
WebDriverWait wait = new WebDriverWait(driver, 10);
try {
WebElement button = wait.until(visibilityOfElementLocated(By.className("_2hc0g")));
button.sendKeys(text);
button.sendKeys(Keys.ENTER);
}catch (Exception e3){
try {
// driver.findElement(By.className("_saf51")).click();
driver.findElement(By.className("_saf51")).sendKeys(text);
driver.findElement(By.className("_saf51")).sendKeys(Keys.ENTER);
}catch (Exception e){
try {
Thread.sleep(500);
// driver.findElement(By.className("_2hc0g")).click();
driver.findElement(By.className("_2hc0g")).sendKeys(text);
driver.findElement(By.className("_2hc0g")).sendKeys(Keys.ENTER);
}catch (Exception e2){
try {
Thread.sleep(500);
// driver.findElement(By.linkText("Add a comment…")).click();
driver.findElement(By.linkText("Add a comment…")).sendKeys(text);
driver.findElement(By.linkText("Add a comment…")).sendKeys(Keys.ENTER);
}catch (Exception e1){
errror++;
if (errror<=3){
sendKomment(saitKomment, text);
}else{
System.out.println("написало ошибку при Add a comment…");
e1.printStackTrace();
throw new Exception();
}
}
}
}
}
}
А это то что находится на сайте:
<section class="_saf51 _p8ucm"><form class="_sk455"><textarea aria-label="Add a comment…" class="_2hc0g" placeholder="Add a comment…" style="height: 18px;"></textarea></form></section>