learningQA
learningQA

Reputation: 125

Couldn't click on a link that opens a menu

I'm trying to click on a link after the text "action". The HTML is:

<div _ngcontent-c10="" class="col-md-3" style="padding-left: 20px;">
  <div _ngcontent-c10="" class="card" style="width:100% !important">
     <div _ngcontent-c10="" class="headerText">FLOATS &amp; MOVE</div>
     <hr _ngcontent-c10="">
     <div _ngcontent-c10="" class="text1">action</div>
     <div _ngcontent-c10="" class="text2">
        <a _ngcontent-c10="" class="waves-light" data-toggle="modal" mdbwaveseffect="" style="margin-right: -25%;" type="button">
          <img _ngcontent-c10="" src="assets/co-assets/icon-down-arrow-med.png">
        </a>
     </div>
     <div _ngcontent-c10=""class="text1">from</div>
     <div _ngcontent-c10="" class="text2"> 
        <a _ngcontent-c10="" class="waves-light" data-toggle="modal" mdbwaveseffect="" 
style="margin-right: -25%;" type="button">
           <img _ngcontent-c10="" src="assets/co-assets/icon-down-arrow-med.png"> 
        </a>
     </div>
     <div _ngcontent-c10="" class="text1">to</div>
     <div _ngcontent-c10="" class="text2">
        <a _ngcontent-c10="" class="waves-light" data-toggle="modal" mdbwaveseffect="" style="margin-right: -25%;" type="button">
           <img _ngcontent-c10="" src="assets/co-assets/icon-down-arrow-med.png">
        </a>
     </div>

The XPath I've used is:

//div[./text()='action']/following-sibling::div[1]/a

I've waited explicitly for 20 seconds with the condition ElementToBeClickable as follows:

wait.until(ExpectedConditions.elementToBeClickable(actionDropDown));

The interesting thing is I'm not getting TimeOutException.

Upvotes: 0

Views: 45

Answers (1)

KunduK
KunduK

Reputation: 33384

Seems like Webdriver unable to click on the element.Try the following options to click.

Use Action class

WebElement ele=driver.findElement(By.xpath("//div[@class='text1'][contains(.,'action')]/following-sibling::div[1]/a"));
Actions action=new Actions(driver);
action.moveToElement(ele).click().build().perform();

Use Javascripts executor

WebElement ele=driver.findElement(By.xpath("//div[@class='text1'][contains(.,'action')]/following-sibling::div[1]/a"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);

Upvotes: 1

Related Questions