Reputation: 407
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...
Upvotes: 1
Views: 428
Reputation: 8479
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();
Upvotes: 1