0

How can I clear a text box field for safaridriver using webdriver?

I used this below command which only works for chrome and Firefox but does not work for safari.

driver.findElement(By.id("userEmail")).clear();

braX
  • 11,506
  • 5
  • 20
  • 33
Mel
  • 23
  • 6
  • 1
    Seems like a simple Javascript call ought to work, if Safari somehow dislikes WebDriver. What is the error message you're getting? – Robert Harvey Sep 22 '14 at 14:57
  • i'm getting below error. org.openqa.selenium.StaleElementReferenceException: Element does not exist in cache (WARNING: The server did not provide any stacktrace information) – Mel Sep 22 '14 at 15:26
  • Sounds like the element doesn't exist in the cache. I don't know enough about webdriver to know why; perhaps you added the element dynamically (using Javascript), without telling webdriver about it? – Robert Harvey Sep 22 '14 at 15:31
  • It works for Firefox and Chrome but does not work for safari – Mel Sep 22 '14 at 15:33
  • Yes, I know. You said that already in your question. Since it's a caching problem, you might want to examine how the "cache" is behaving. – Robert Harvey Sep 22 '14 at 15:34

1 Answers1

-1

Clear the element using

function name()
{  
document.getElementById('elementid').value = "";
}
Andrew Spencer
  • 15,164
  • 4
  • 29
  • 48
Izzy
  • 6,740
  • 7
  • 40
  • 84
  • I am new to Webdriver, i don't know what to do with this code – Mel Sep 22 '14 at 15:34
  • Are you using [Selenium WebDriver](http://docs.seleniumhq.org/projects/webdriver/)? – Izzy Sep 22 '14 at 15:46
  • You can refer to this question [Clear text from textarea with selenium](http://stackoverflow.com/questions/7732125/clear-text-from-textarea-with-selenium) – Izzy Sep 22 '14 at 15:57