Button will not click in my code

Hello,

I’m still trying to get the hang of asking the right questions. But in my code I am trying to make a IF statement that if true it clicks “Viewdets” and then click the button “Pay”. However, it will not press “pay” button, after it clicks “viewdata”. So my question is am I missing something in my code to where after “viewdets” is passed it doesn’t click the “pay” button?

if (!driver.findElements(By.id(viewdets)).isEmpty()) {
        driver.findElement(By.id(viewdets)).click();
        
    //App Closes and Doesn't Click Pay Button
        driver.findElement(By.id(pay)).click();
        driver.findElement(By.id(conpay)).click();
    //If not then continue to stall and check in
    } else {
        Thread.sleep(7000);
        driver.findElement(By.id(stall)).click();
        driver.findElement(By.id(two)).click();
        driver.findElement(By.id(three)).click();
        driver.findElement(By.id(next)).click();

        wait = new WebDriverWait(driver, 15);
        wait.until(ExpectedConditions.elementToBeClickable(By.id(pay)));

        driver.findElement(By.id(pay)).click();
        driver.findElement(By.id(conpay)).click();
        driver.findElement(By.id(receipt)).click();

One thing you will find about Appium is that it moves much faster than the normal user. If the state of the App is in flux Appium may try to click a button before it even exists! Therefore it is important to wrap any interaction like this in an implicit wait:

http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

2 Likes

as Wreed said, try adding a sleep after viewdets click event. If this doesn’t help paste the error logs here to debug and is this related to iOS or Android app?

First, I never said that. Second, don’t just indiscriminately add explicit time after a click event! Much better to follow the link and add an implicit wait to the click itself.

you have code:

driver.findElement(By.id(viewdets)).click();
driver.findElement(By.id(pay)).click();
  1. does “pay” button available/visible on screen BEFORE tap on “viewdets” ?
  2. when you do click on “pay” button does anything change on screen?
1 Like

sorry for that[quote=“wreed, post:4, topic:18702”]
First, I never said that. Second, don’t just indiscriminately add explicit time after a click event! Much better to follow the link and add an implicit wait to the click itself.
[/quote]

Sorry for that, I will work on moving my scripts from sleep to implicit wait. And thanks for the link :+1:

1 Like