0

I have HTML as below

<div class="summary-row">
    <div class="text-center" id="summary-back">
        <a href="/Health/Dependents">
            <svg class="svg-inline--fa fa-chevron-left fa-w-8 font-32" data-auto="back-btn" aria-hidden="true" data-prefix="fal" data-icon="chevron-left" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512" data-fa-i2svg=""><path fill="currentColor" d="M238.475 475.535l7.071-7.07c4.686-4.686 4.686-12.284 0-16.971L50.053 256 245.546 60.506c4.686-4.686 4.686-12.284 0-16.971l-7.071-7.07c-4.686-4.686-12.284-4.686-16.97 0L10.454 247.515c-4.686 4.686-4.686 12.284 0 16.971l211.051 211.05c4.686 4.686 12.284 4.686 16.97-.001z"></path></svg><!-- <i class="fal fa-chevron-left font-32" data-auto="back-btn"></i> -->
        </a>
        </div>

And RemoteWebDriver unable to find the element and I assume its due to the hidden attribute, How can click on this element ?

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Rasika
  • 293
  • 1
  • 6
  • 18

3 Answers3

0

You can click on the element using JavaScriptExecutor like:

WebElement element = driver.findElement(By.id("summary-back"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Sameer Arora
  • 4,161
  • 2
  • 6
  • 20
0

To click() on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div.summary-row > div#summary-back > a[href=/Health/Dependents]"))).Click();
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='summary-row']/div[@id='summary-back']/a[@href='/Health/Dependents']"))).Click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
0

I just changed attribute "aria-hidden" from "true" to "false" and after that I clicked.

Perhaps that code can help you.

public void ClickElementHidden()
{
((IJavaScriptExecutor)driver).ExecuteScript("document.getElementsByClassName('svg-inline--fa fa-chevron-left fa-w-8 font-32')[0].setAttribute('aria-hidden', 'false')");
driver.FindElement(By.CssSelector("#summary-back > a > svg")).Click();   
}