java-client
java-client copied to clipboard
Unable to wait for a reply while using actions class in Selenium webdriver.
Description
I am trying to automate whatsapp web. I use actions class in Selenium webdriver in Java. I am able to click on click and write the message and send to chat using action class. But, actions class performs all actions one after the other. I need to wait for the reply to come for the sent message.
Environment
-
Desktop OS/version : Windows 10
-
Real device or emulator/simulator: Whatsapp web
Details
Please provide more details, if necessary.
Code To Reproduce Issue [ Good To Have ]
System.setProperty("webdriver.gecko.driver","//Path//"); driver=new FirefoxDriver(); driver.get("https://web.whatsapp.com/"); driver.manage().window().maximize(); System.out.println("website open");
WebDriverWait waits =new WebDriverWait(driver,30);
waits.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"app\"]/div/div/div[4]/div/div/div[1]")));
WebElement oo=driver.findElement(By.xpath("//*[@id=\"pane-side\"]/div[1]/div/div/div/div/div/div[2]"));
oo.click();
Thread.sleep(2000);
WebElement text=driver.findElement(By.xpath("//div[@class='_3uMse']"));
Actions action= new Actions(driver);
action.moveToElement(text).build().perform();
text.click();
System.out.println("type text clicked");
Thread.sleep(2000);
action.sendKeys("Hi");
action.sendKeys(Keys.ENTER);
//action.pause(8);
String last_str=div_fun();
Thread.sleep(5000);
System.out.println(last_str);
WebElement option=driver.findElement(By.xpath("//div[@class='PVMjB']//div[@title='Menu']"));
action.moveToElement(option).build().perform();
option.click();
Thread.sleep(2000);
WebElement logout=driver.findElement(By.cssSelector("#side > header > div._3euVJ > div > span > div.PVMjB._4QpsN > span > div > ul > li:nth-child(7) > div"));
logout.click();
System.out.println("Logout from device");
driver.close();
}
public static String div_fun () throws InterruptedException { List<WebElement> divs=driver.findElements(By.xpath("//div[@class='eRacY']//span[@class='_3Whw5 selectable-text invisible-space copyable-text']")); int n=divs.size(); //System.out.println("Number of divs "+n); String name=null;
for(WebElement i:divs )
{
name =i.getText();
}
return name ;
}}
Exception Stacktraces
Please create a gist with the pasted stacktrace of the exception thrown by java.
Link To Appium Logs
Please create a gist which is a paste of your full Appium logs, and link them here. Do not paste your full Appium logs here, as it will make this issue very long and hard to read! If you are reporting a bug, always include Appium logs as linked gists! It helps to define the problem correctly and clearly.