I have an id of my web element, for now I can click on it but I need to check whether it is top/bottom/middle of the page using selenium
CodePudding user response:
If you use nodejs, something like this:
const getPosition = () => {
var element = document.getElementById('myElement');
var pos = element.getBoundingClientRect().top / window.innerHeight;
if (pos < 0.35){
return "top";
}else if(pos > 0.75){
return "bottom";
}else{
return "center";
}
}
const position = await driver.executeScript(getPosition);
So, inject script, and await for return, in the script check the height relative to the window size, you need to improve the script in the example considering the case where the id isn't visibile (pos < 0 and pos > 1)