0

I am trying to do some testing in a headless browser, to test filling in a form.

I am using code that I was shown from the following example :

github link to example of using phantomjs

My code :

WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get("<URL HERE, left out for privacy on stack overflow!>");
By amount = By.id("amountField");
wait.until(ExpectedConditions.presenceOfElementLocated(amount));

Error in intelliJ :

until(java.util.function<? super org.openqa.selenium.WebDriver, V) in FluentWait cannot be applied to : 

(org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement>)

I am not really sure where I am going wrong here - but I have spent two hours trying to fix this issue.

element I am looking for on page :

<input name="amount0" id="amountField" value="" class="amount form-control" type="number" pattern="\d+(\.\d*)?" maxlength="10" placeholder="Amount">
3
  • Can you be a bit specific about your​ question ? 1. What is your objective? 2. What are you trying to achieve? 3. Why do you need an Explicit Wait ? 4. Is it a hidden element? 5. How does it appears? 6.Provide the HTML DOM. Commented Mar 16, 2017 at 19:32
  • Please read the above as Fluent Wait instead of Explicit Wait. Commented Mar 16, 2017 at 19:34
  • Trying to test the filling out of a form, I need the fluent wait, because phantomjs seems to try and get the element before it loads. Element is not hidden. It appears as a test box. Unfortunately I do not have the full DOM of the page, but will paste the element into the main question right now. Commented Mar 16, 2017 at 20:10

1 Answer 1

1

Seems that the issue is not with PhantomJS. The error you see tells it all.

Your code seems to considering the WebDriverWait wait as a Fluent Wait where as you have exported import org.openqa.selenium.support.ui.ExpectedConditions; which is causing the error.

In the documentation as well, the author have used Explicit Wait importing import org.openqa.selenium.support.ui.ExpectedConditions; and import org.openqa.selenium.support.ui.WebDriverWait;

I would suggest you to try this approach:

  1. Let the url get loaded first.
  2. Define the Explicit Wait.
  3. Define the ExpectedConditions in untill.
  4. Get the status of the Element.
  5. Sysout the Status.
  6. If it fails, increase the duration of Explicit Wait to fulfill ExpectedConditions.

You can have a look at this modified code:

driver.get("<URL HERE, left out for privacy on stack overflow!>");
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("amountField")));
        boolean status=element.isDisplayed();

        if (status)
        {
            System.out.println("Element is displayed");
        }
        else
        {
            System.out.println("Element is not displayed");
        }

Let me know if this helps you.

Sign up to request clarification or add additional context in comments.

3 Comments

Did you get a chance to look at this solution ?
Sorry - took me a while to get back to you - my brother is dying, and that is sometimes something that takes me away from my daily activities.
I'm glad to be able to help you out. Take care.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.