I am working on a project in selenium, in which once it fills out a textbox, clicks next page, a captcha comes up. First you need to verify, then the captcha shows up. It is just a pop up box in the middle of the page and makes everything else unclickable with a white haze over the page behind it. Once the verification is clicked on I already have a method for solving the captcha.
The issue I am having is that with the methods I have tried, the webdriver cannot seem to find any trace of this button. I always get an no such element exception
, when trying to use click()
. I have tried wait.until(ExpectedConditions.elementToBeClickable(By.id("home_children_button"))).click();
, wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("home_children_button")))).click();
, I have also tried putting a thread.sleep(Num)
instead of using a wait, along with many other methods on google. Then when I did some research about href buttons, I found people recommend to use By.linkText
. So I tried that with all the methods I tried before, and element still cannot be located. I couldn't find anything else on google, so I thought I would ask for help.
I have attatched the HTML Code I currently am looking at for the button, along with the link for the website. Unfortunately to encounter this page, you must make an account. This page normally comes up once I put the DOB in. Thank you for any clarification provided.
<a href="javascript:;" id="home_children_button" class="sc-bdfBwQ jXXvQg sc-kEjbxe hVNnSn">Verify</a>
https://account.battle.net/creation/flow/creation-full
Code I have tried:
wait2.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("fc-iframe-wrap")));
wait2.until(ExpectedConditions.elementToBeClickable(By.id("home_children_button"))).click();
WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("CaptchaFrame")));
wait2.until(ExpectedConditions.elementToBeClickable(By.id("home_children_button"))).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("home_children_button"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("home_children_button"))).click();
,
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("home_children_button")))).click();
Thread.sleep(5000) //wait for it to pop up
driver.findElement(By.id("home_children_button"))).click();
Along with trying to use By.linkText
.
Solution: After being told it's an iframe, I looked closer at the HTML to see there was multiple iframes. So I waited to switch through them in order to click the button.
WebDriverWait wait2 = new WebDriverWait(driver, 20);
wait2.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("/html/body/div[4]/iframe")));
wait2.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("/html/body/div/div[1]/div/iframe")));
wait2.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("/html/body/div[1]/div[2]/div[1]/iframe")));
wait2.until(ExpectedConditions.elementToBeClickable(By.id("home_children_button"))).click();
As I suspected, it is in iframe, you need to switch the focus of your driver to interact with verify button :
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("CaptchaFrame")));
wait.until(ExpectedConditions.elementToBeClickable(By.id("home_children_button"))).click();
and once you are done with it, you may want to use defaultContent()
driver.switchTo().defaultContent();