I read a post on SOF here and tried to follow it in my own problem solving but I made myself more problem than a solution.
I tried to findElements, targeting an array of
<img id="4444" class="someclass" src="/images/animg.png" onclick="doSomething(this)" title="contact person Name"/>
from a website, and I'd like to further click on each in a loop and perform operations per each.
As all img tag has attribute "src=/images/animg.png", I wrote:
drv.wait(until.elementLocated(By.xpath(".//*[@src='/images/animg.png']")), 10000, 'img not appeared');
drv.findElements(By.xpath(".//*[@src='/images/animg.png']")).then(function (imgs) {
let myimgs = imgs.map(function (elem) {
elem.getAttribute("src").then(function (x) {
return elem; //or try elem.getAttribute("src");
});
});
thepromise.all(myimgs).then(function (allit) {
console.log('y: ' + allit[0]);
});
});
The confusion:
1. if I issue "return elem", to further do "elem.click()", I get a promise object (using util.inspect easily seen)
2. I made a conclusion, that this elem, is a promise object
3. if I issue "return elem.getAttribute("src");" I have the src returned, that makes me think that elem is NOT a promise, but the
4. unfortunately, trying to issue "allit[0].click()" which is "elem.click()" fails as it shows a promise object!
So I am confused what is really happening there. Could you please explain? (I googled half a day and still can not understand anywhere).