1

I'm using a library "Selenium" on Java to write a script to perform online tasks. It works perfectly fine on sites like facebook, youtube, etc. For some reason, in this website it does not: kingdoms.com . The button I want to click has this line of code:

<a data-mellon-iframe-url="/authentication/login" id="loginButton" data-selector="#mellonModal" class="jqFenster"><button> <span>Entrar</span></button></a>

The code I wrote for that is:

 driver.findElement(By.id("loginButton")).click(); 

And it does not click. But if I print this line:

     System.out.println(driver.findElement(By.id("loginButton")).getText()); 

it prints "Entrar", so the script knows the button but for some reason it won't click it.

Any idea? I've tried putting the script on sleep for 3s before clicking, for the case the button wasn't load on time, but it didn't fix it...

6
  • in kingdoms.com, i dont see login button as you shown in html example. Commented Nov 2, 2018 at 19:27
  • is on the top right corner. A green one @Navarasu Commented Nov 2, 2018 at 19:28
  • but it doesn't have text like Entrar. it showing this <a data-mellon-iframe-url="/authentication/login" id="loginButton" data-selector="#mellonModal" class="jqFenster"> <button><span>Login</span></button> </a> Commented Nov 2, 2018 at 19:30
  • are u gettiing error while clicking? Commented Nov 2, 2018 at 19:31
  • It's on the next line, but that should not matter. The id is loginButton, so why does it now work properly? Commented Nov 2, 2018 at 19:31

1 Answer 1

1

Actually the anchor tag is hidden behind button tag. You need to click the button which is inside anchor tag. I tried with css selector and it works

driver.findElement(By.cssSelector("#loginButton button").click()

Add wait for the button before clicking,

    driver.get("https://www.kingdoms.com/");
    WebDriverWait wait = new WebDriverWait(driver, 60);
    WebElement loginBtn= wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#loginButton button")));
    loginBtn.click();
Sign up to request clarification or add additional context in comments.

4 Comments

I was using Thread.sleep() to wait. It does work!!! Thanks a lot, but where did you see that "#loginButton button" ? Since that the login box (the email and password) seem to have the same issue!
That is a different case. user name and password is present in iframe. I see it is iframe inside iframe. You need to switch to first iframe and then to next iframe. Check this post stackoverflow.com/questions/23302769/… Then try to sendkeys to username and password
Im sorry, but this is not something that I am familiar with. Could you explain please, that post wasn't very enlightening for me. Why can't I access it by By.name("email") ?
Refer this blog to understand iframe guru99.com/handling-iframes-selenium.html

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.