Sunday, January 12, 2025

java – Methods to learn the row quantity with having column knowledge?


There isn’t a easy strategy to discover the factor’s mother or father if you have already got a toddler in WebElement if you use WinAppDriver. Nevertheless you should use the work-around the thought of which I reveal within the under instance:

public static void principal(String[] args) throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
    WindowsDriver driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);
    WebElement factor = driver.findElementByAccessibilityId("num8Button");
    WebElement parentElement = findParent(factor, driver);
    System.out.println(parentElement.getAttribute("Identify"));
    driver.stop();
}

static WebElement findParent(WebElement little one, WebDriver driver){
    String automationId = little one.getAttribute("AutomationId");
    return driver.findElement(By.xpath("//*[./*[@AutomationId='" + automationId + "']]"));
}

Code rationalization:

Principally, right here you introduce helper technique that takes your factor, extracts AutomationId attribute worth and builds xpath question ranging from the highest of the dom. That question is in-built the best way to search out all the weather which have a minimum of one little one factor having the given AutomationId. So when you’ve got the construction like this:

root
|
+-- el1
|    |
|    +-- el2 [AutomationId = 'blahblahId']
|
+-- el3

And in case you go el2 to that technique, then it extracts worth blahblahId and construct the next xpath question: //*[./*[@AutomationId='blahblahId']]. This question will return factor el1

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com