Winium.Desktop
Winium.Desktop copied to clipboard
Couldn’t perform the action like Click(), but same xpath worked for getAttribute() in Winium Java code
Code: public class MyFirstTestCase { public static void main(String[] args) throws MalformedURLException, Exception { DesktopOptions option = new DesktopOptions(); option.setApplicationPath("C:\Windows\System32\calc.exe"); WiniumDriver driver = null; int port = 9999; String WiniumEXEpath = "D:\Winium\Winium.Desktop.Driver.exe"; File file = new File(WiniumEXEpath); Runtime.getRuntime().exec(file.getAbsolutePath()+" --port "+port); try { driver = new WiniumDriver(new URL("http://localhost:"+port),option); } catch (MalformedURLException e) { e.printStackTrace(); } Thread.sleep(5000);
**driver.findElement(By.id("num7Button")).click();** // Not Work getting below mentioned error
String acutalResult = driver.findElement(By.id("CalculatorResults")).getAttribute("Name");
System.out.println("Result is :- " + acutalResult);
}
}
Error: Exception in thread "main" org.openqa.selenium.NoSuchElementException: Element cannot be found (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 53.60 seconds
By num7Button = By.id("num7Button");//Locator
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(num7Button)).click();
if the previous solutions didnt work, then try findelements
size = driver.findElements(By.id("num7Button")) .size() If size = 0 then the element is not present in the screen.