dman
dman

Reputation: 11073

Protractor not finding element- all looks correct

Protractor is not finding this element.....it's driving me crazy. Any ideas why? The element does exist...I verified it in the dev console.

<download
  path="api/backup_jobs/errors.csv"
  params="errorsFilter"
  class="header-action">
  Download Filtered CSV
</download>

element(By.css('[path^="api/backup_jobs"]')).getAttribute('path');

element(By.css('download[params["errorsFilter"]')).getAttribute('path');

Upvotes: 1

Views: 442

Answers (1)

alecxe
alecxe

Reputation: 474221

I don't think this selector is correct:

element(By.css('download[params["errorsFilter"]')).getAttribute('path');

You've probably meant instead:

$("download[params=errorsFilter]").getAttribute('path');

Also check that the element is not inside an iframe - if it is, you would need to switch into the context of the frame using switchTo(), before searching for the element:

browser.switchTo().frame("frame_name_or_id");  

And, if this is a "timing" issue, you can explicitly wait for the element to be present:

var EC = protractor.ExpectedConditions,
    elm = $("download[params=errorsFilter]");

browser.wait(EC.presenceOf(elm), 5000);  // wait up to 5 seconds

expect(elm.getAttribute('path')).toEqual("api/backup_jobs/errors.csv");

Upvotes: 3

Related Questions