Tester_at_work
Tester_at_work

Reputation: 99

Unable to click on element defined in Div Class

I am trying to automate a mobile app testing using Eclipse. However, I am facing an issue where I can't perform a click() action.

This is my test code:

public class Firstflow {
    static DesiredCapabilities dc = new DesiredCapabilities();
    @SuppressWarnings("rawtypes")
    static AndroidDriver driver;
    @SuppressWarnings("rawtypes")
    public static void main(String[] args) throws MalformedURLException, InterruptedException{              
        dc.setCapability("deviceName", "emulator-5444");
        dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.mol.molwallet.uat");
        dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.mol.molwallet.module.start.SplashActivity");
        driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
        driver.setLogLevel(Level.INFO);
        Thread.sleep(5000); 
        driver.findElement(By.className("_highlighter-box_619e8 _inspected-element-box_619e8")).click();
        driver.findElement(By.xpath("//*[@text='LOG IN']")).click();
        driver.findElement(By.xpath("//*[@text='Region']")).click();
        driver.findElement(By.xpath("//*[@text='Malaysia']")).click();
        driver.findElement(By.xpath("//*[@id='etAccount']")).sendKeys("123456");
        driver.findElement(By.xpath("//*[@text='NEXT']")).click();
    }
}

The line of code in question is the driver.findElement(By.className("_highlighter-box_619e8 _inspected-element-box_619e8")).click();

I need to click on the link "SKIP" as highlighted in the screenshot below. The element's detailed is also shown as per highlighted. enter image description here

I have tried By.xpath and now By.className, both of which will result in the error (Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.)

Hope to have advice to resolve this issue.

Upvotes: 0

Views: 45

Answers (2)

Dmitri T
Dmitri T

Reputation: 168217

It's better to paste page source as code, not as image, the chance you'll get comprehensive answer will be much higher so next time consider executing driver.getPageSource() command and paste the text here.

As we cannot see the full page source I can give only a "blind shot": try using normalize-space() function like:

//div[normalize-space()='SKIP'] | //div/child::*[normalize-space()='SKIP'] | //div/descendant::*[normalize-space()='SKIP']

More information:

Upvotes: 1

dhulipala murali
dhulipala murali

Reputation: 193

This is very simple.Use the dynamic xpath something like below in your code

//*[contains(text(),'Skip']

Upvotes: 1

Related Questions