1

I tried WebDriverWait, .click(), .sendKeys(Keys.RETURN), implicitWait, explicitWait and many more methods, but I'm unable to click on this web element.

<div class="actions style-scope tv-overlay-record-on-the-go">
  <tv-button pill-action="" class="style-scope tv-overlay-record-on-the-go x-scope tv-button-2 left"><button class="style-scope tv-button"><div class="wrapper style-scope tv-button"><iron-icon id="icon" class="style-scope tv-button x-scope iron-icon-0"></iron-icon><div id="content" role="presentation" class="style-scope tv-button">Got it</div></div></button>
    <div
      class="hover-hint style-scope tv-button"> </div>
</tv-button>
</div>

Based off the above HTML code, I created the following xpath:

WebElement gotIt = driver.findElement(By.xpath("//div[@class='actions style-scope tv-overlay-account-active']//div[@id='content']"));

gotIt.click();

I believe the code runs and acknowledges that the button is there, and thus the web element is created successfully. But, when I try to interact with it by using the many interaction methods, nothing happens.

enter image description here

Exception I got: org.openqa.selenium.ElementNotInteractableException: element not interactable

2
  • what exception you getting, please add those in question. Additionally check if if is inside iframe or not Commented Nov 25, 2019 at 15:32
  • check 'Got It' button is present on the iframe or not. If so then you have to switch to it before pressing any button. Commented Nov 25, 2019 at 15:40

3 Answers 3

1

I would try querying on the text rather than just ID attribute of div -- your XPath might be returning many results, and clicking on the first one, which is why nothing happens.

I would try this:

WebElement gotIt = driver.findElement(By.xpath("//div[@class='actions style-scope tv-overlay-account-active']//div[text()='Got it']"));

//gotIt.click(); throws element not interactable

// you can also try Javascript click -- work around element not interactable issue
((JavascriptExecutor)driver).executeScript("arguments[0].click();", gotIt);

I changed your XPath to query on the 'Got it' text rather than the ID attribute content which may be returning multiple results. I also included code to execute a Javascript click, which may help as a workaround to any click issues.

The Xfinity website seems to have many iframe elements, but I can't get to your specific page to check and see, so this may or may not be causing an issue as well.

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

6 Comments

I'm able to access this page after clearing xfinity cache. This code looks like it should work, but I'm getting element not interactable. I've tried this type of execution on different URLs and it works flawlessly. Maybe it is an iframe element, will have to look into that. I'm kinda new at this.
@MayankYadav Remove gotIt.click(); and just run the executeScript line. This will workaround ElementNotInteractable.
I removed gotIt.click(); and the program passed both the tests. But, it didn't click the Got it button at all.
What happens if you print driver.findElements(By.xpath("//div[@class='actions style-scope tv-overlay-account-active']//div[text()='Got it']")).size();? I am wondering if this selector is locating multiple elements on the page, and that's part of the problem here.
That's exactly what the problem was. I found out that it was running into 4 different elements. I made the xpath more concise and it worked. Thanks for all your help! WebElement gotIt = driver.findElement(By.xpath("//tv-button[@class='style-scope tv-overlay-record-on-the-go x-scope tv-button-2 left']/button[@class='style-scope tv-button' and 1]"));
|
0

Check your button isn't on the iframe if not then you can find below XPath using contains to click on the Got it button

WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(text(),'Got it')]")));
element1.click();

Solution 2:

WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(text(),'Got it')]")));
Actions builder = new Actions(driver);
Action buttonClick = builder.moveToElement(element1).click().build();

5 Comments

Got the same error as I usually do. element not interactable.
Check updated solution and also check you are not in the iframe otherwise you need to switch to iframe , This exception is telling element is present on the HTML DOM, but it's not in the state that can be interacted with
After performing this action, it still isn't clicking the Got it button. Expected condition failed: waiting for element to be clickable: By.xpath: //div[contains(text(),'Got it')] (tried for 10 second(s) with 500 milliseconds interval)
Ok I think you need to switch to iframe share your link or complete html. Or just try driver.switchto.frame(1) before performing click on a got it button
File is too large to attach.
0

Please try Action Object for clicking like following :

    WebElement gotIt = driver.findElement(By.xpath("//div[@class='actions style-scope tv-overlay-account-active']//div[@id='content']"));

    Actions actions = new Actions(driver);
    actions.moveToElement(gotIt).click().build().perform();

1 Comment

Tried that solution since Dipak suggested it. Didn't work.

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.