javascript - Selenium - Unable to find the hidden element -
i trying create framework want find whether webelement hidden or not before performing action on web element.
i have password field hidden , structured below
<div class=hidepassword> <input password field > <div> when query input tag following lines
isvisible1 = (string)js1.executescript("return (window.getcomputedstyle?window.getcomputedstyle(arguments[0], null):arguments[0].currentstyle).visibility;", mycurelement); isvisible2 = (string)js1.executescript("return (window.getcomputedstyle(arguments[0], null).getpropertyvalue('display'));", mycurelement); isvisible3 = (bool)js1.executescript("return !(arguments[0].offsetheight <= 1);", mycurelement); i getting values indicating visible.
later , got know class preceding div has making input invisible. tried value of overflow made available in .css file class hidepassword
but unfortunately, there lot of css values class hidepassword , when use below javascript function, able 1 of css value
public string getstyle(string classname) { ijavascriptexecutor js = (ijavascriptexecutor)driver; return (string)js.executescript( "function getstyle(classname) {" + "var stylesheets = window.document.stylesheets;" + "var stylesheetslength = stylesheets.length;" + "for (var = 0; < stylesheetslength; i++)" + "{" + " var classes = stylesheets[i].rules || stylesheets[i].cssrules;" + " if (!classes)" + " continue;" + " var classeslength = classes.length;" + " (var x = 0; x < classeslength; x++)" + " {" + " if (classes[x].selectortext == classname)" + " {" + " var ret;" + " if (classes[x].csstext)" + " {" + " ret = classes[x].csstext;" + " }" + " else" + " {" + " ret = classes[x].style.csstext;" + " }" + " if (ret.indexof(classes[x].selectortext) == -1)" + " {" + " ret = classes[x].selectortext + ret ;" + " }" + " return ret;" + " }" + " }" + "}" + "}return getstyle(arguments[0]);", classname); } is there way css values particular class name , based on css values class, can make call whether element visible or not visible. ?
thanks in advance on this.
selenium had supply api:isdisplayed() detect element visibility, why want implement such complex
Comments
Post a Comment