While executing scripts getting error as "Exception in thread "main" org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions"

2,453 views
Skip to first unread message

Sachu Sunny

unread,
Dec 8, 2013, 4:11:38 AM12/8/13
to webd...@googlegroups.com
Hi all,

While i am executing below script in Firefox

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;




public class test {
public static void main(String ars[]) throws InterruptedException 
{
WebDriver ch=new FirefoxDriver();
Thread.sleep(60);
ch.findElement(By.xpath("//*[@id='gs_tti0']")).sendKeys("selenium");
}

}

getting error as below
Exception in thread "main" org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions
Command duration or timeout: 17 milliseconds.

please advice me how to resolve this.

Andreas Tolfsen

unread,
Dec 9, 2013, 7:35:02 AM12/9/13
to webd...@googlegroups.com

sachus...@gmail.com writes:

> While i am executing below script in Firefox

[…]

> getting error as below
>
> Exception in thread "main"
> org.openqa.selenium.InvalidElementStateException: Element is disabled
> and so may not be used for actions Command duration or timeout: 17
> milliseconds.

You cannot send keys to an element that is disabled.

Chris Merrill

unread,
Dec 9, 2013, 9:57:53 AM12/9/13
to webd...@googlegroups.com
On 12/8/2013 4:11 AM, Sachu Sunny wrote:
> getting error as below
> Exception in thread "main" org.openqa.selenium.InvalidElementStateException: Element is disabled and
> so may not be used for actions
> Command duration or timeout: 17 milliseconds.
>
> please advice me how to resolve this.

A real user can't type text in a disabled field and neither can WebDriver. You either
need to:
- perform the action that a human would perform in order to enable the field
- or, if a human CAN type the text in the field, you probably have the wrong
element. You need to find the correct element.

Chris


--
------------------------------------------------------------------------ -
Chris Merrill | Web Performance, Inc.
ch...@webperformance.com | http://webperformance.com
919-433-1762 | 919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

Piotr Szymanski

unread,
Dec 9, 2013, 10:46:30 AM12/9/13
to webd...@googlegroups.com
Hello,

-ch.findElement(By.xpath("//*[@id='gs_tti0']")).sendKeys("selenium");
+ch.findElement(By.name("q")).sendKeys("selenium");

Thanks,
P.


2013/12/9 Chris Merrill <ch...@webperformance.com>

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

saranya

unread,
Dec 10, 2013, 7:49:59 AM12/10/13
to webd...@googlegroups.com
Hi,
 
Please check for the webelement is visible or enabled  and then proceed to do action over that.
 
Eg.
 
System.out.println(webelement.isenabled());
 
If it returns true then proceed.
 
Thanks,
Saranya

Vishnu Varma

unread,
Jun 10, 2014, 10:59:12 PM6/10/14
to webd...@googlegroups.com
Hi Sachu,

If you spy on the "Google Search Text box", you can notice that element is Disabled. In this case, you cannot use XPath. Please use ClassName to send keys and it works fine. Please find the below HTML inspection on Textbox.

input
 id="gs_htif0" class="gbqfif" disabled="" autocomplete="off"

Manisha Kaur

unread,
Dec 13, 2016, 5:52:52 AM12/13/16
to webdriver, a...@mozilla.com

driver.findElement(By.name("q")).sendKeys("Selenium");
Reply all
Reply to author
Forward
0 new messages