0

I started to learn Selenium this morning lol but i'm stuck trying to click on a element like this:

<a rel="nofollow" style="" href="javascript:void(0);" time="" itemid="1523208" data-has-req="0" class="button okletsdothis nonsubscriber dl button-green" title="Download">
  <span class="icon-download" time="" itemid="1523208"></span>
  Download
</a>

In the console I'm getting this error

ElementNotInteractableError: element not interactable

This is the code where I wait until the element is located and then try to perform the click action

let downloadButton = await driver.wait(
    until.elementLocated(
      By.xpath(
        '(//a[@class="button okletsdothis nonsubscriber dl button-green"])'
      )
    ),
    100000,
    "Timed out after 30 seconds",
    5000
  );

await downloadButton.click();

If I change the xpath and click on a element like this

By.xpath('(//div[@class="download-button ide"])')

it works fine, but in the case before i can't make it work. Please help.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
cetaphil
  • 35
  • 4
  • Both the xpaths are different.. Not sure wht you want to ask.. you not only changed the xpath but also changed the element – Kumar Rishabh Jan 17 '21 at 18:08
  • I wanted to show that with another element like a div the click seems to trigger right, but with the anchor element it doesn't work ... The question is why I'm getting that error with the anchor element – cetaphil Jan 17 '21 at 18:17
  • did the link works manually? I doubt as it has href="javascript:void(0); means it will do nothing on click – Kumar Rishabh Jan 17 '21 at 18:28
  • use until element is clickable instead of wait until the element is located.. it the link works manually, then it should help – Kumar Rishabh Jan 17 '21 at 18:35

1 Answers1

0

To click on the element with text as Download you can use the following Locator Strategies:

let downloadButton = await driver.wait(
    until.elementLocated(
      By.xpath(
    '(//a[@class="button okletsdothis nonsubscriber dl button-green" and @title="Download"])'
      )
    ),
    100000,
    "Timed out after 30 seconds",
    5000
  );

await downloadButton.click();

Or

let downloadButton = await driver.wait(
    until.elementLocated(
      By.xpath(
    '(//a[@class="button okletsdothis nonsubscriber dl button-green" and @title="Download"]/span[@class="icon-download"])'
      )
    ),
    100000,
    "Timed out after 30 seconds",
    5000
  );

await downloadButton.click();
DebanjanB
  • 118,661
  • 30
  • 168
  • 217