How to find element visible status....is this selenium bug or limitation ????

3,001 views
Skip to first unread message

Vinothkumar Velusamy

unread,
Jun 18, 2013, 10:23:10 AM6/18/13
to seleniu...@googlegroups.com
Hi,

consider below code....

<div id = "Parent" style = "display : block">
    <div id = "child_1">
       <div id = "child_2">
          <div id = "child_3">
             <input id ="input_1" type = "text">
          </div>
      </div>
   </div>
</div>

now if i need to get the input path, i am doing by //input[@id="input_1"].. this will identify input path. suppose , if "style = "display : block"" is set to parent as mentioned in the above code, this is getting displayed in the html page , works fine with automation also.

if i change the style to set as  "style = "display : none", then the page will not display in the browser since the style is setted as none for the parent level. now if i execute the script which contains the code for  //input[@id="input_1"] alone, the findelementbyXpath able to find the element though it is not visible to the user level. 

now the question is :
how to get whether the parent style is set to none or not. Please note; i dont want to travel from parent path to child path.. i mean , i dont want to start from "//div[@id = "Parent" and contains[@style = "display : block"]]/div/div/div/input...
rather i need to find the parent of particular element dynamically.......... in this case... div id=parent ......

Thanks for the info in advance...

regards
Vinothkumar Velusamy

shammi

unread,
Jun 18, 2013, 3:04:59 PM6/18/13
to seleniu...@googlegroups.com
If you are changing style  "style = "display : none", then it won't find element because webdriver doesn't work on hidden elements.

Krishnan Mahadevan

unread,
Jun 18, 2013, 8:47:20 PM6/18/13
to seleniu...@googlegroups.com
@Shammi,
That's not true. AFAIK the only time when WebDriver would throw an error is when it cannot find an element in the DOM. 

Irrespective of whether an element is *visible* or not WebDriver would find the element but it will only interact with visible elements to the user. 
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0f5d05c4-754b-4f4a-a32a-398171648478%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

Vinothkumar Velusamy

unread,
Jun 21, 2013, 2:53:18 PM6/21/13
to seleniu...@googlegroups.com
Any idea guys how to identify the style of the parent .... from my example ? ? ? ? ? 


For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Best Regards,
Vinoth V
Cell:+91-9740-629-246

sirus tula

unread,
Jun 21, 2013, 3:07:41 PM6/21/13
to seleniu...@googlegroups.com
Hi Vinoth,

I think you can check if the element is visible or not by writing the following statements. The statement below will check if the element is present/displayed and clicks it if it is displayed.

if(driver.findElement(By.cssSelector("input#input_1")).isDisplayed())
{
   driver.findElement(By.cssSelector("input#input_1")).click();
}

Hope that helps.



For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
 
- "If you haven't suffered, you haven't lived your life."
 
Thanks,
 
Sirus
Reply all
Reply to author
Forward
0 new messages