I have some thing like there is a toggle button of having "Show" and "Hide" as values, I want to know the status of the button before i am going to perform some action on this toggle button. The code looks like:

<td class="OC_hide_show">
<div class="toggle">
<select id="id1" class="some class name" data-role="isnsd"   name="selectcommand">
<div class="some class names" role="application">
<span class="Some class names" role="img" style="width: 0%;">Show</span>
<span class="some class names" role="img" style="width: 100%;">Hide</span>          
<div class="ui">


The logical guess would be checking the element property:

bool isDisplayed = driver.findElement(By.XPath("//span[text()='Show']").isDisplayed;

Should this not work (because you're using the CSS width instead of CSS display), try:

String s = driver.findElement(By.XPath("//span[text()='Show']").getAttribute("style");
  // the show button is visible
  // the hide button is presumably visible
  • That helped me in solving the problem.However as per my knowledge we are not suppose to use "style" attribute to find the element status. Please correct if am wrong. – Dasoju Shiva Feb 23 '15 at 6:35
  • @DasojuShiva Yes, using attributes to determine a status is just a workaround if the element properties are not sufficient. If your problem is resolved, please mark my reply as answer (check the V mark) so the question doesn't remain open. – FDM Feb 23 '15 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.