1

I am new to selenium and have encountered a syntax anomaly that I cannot figure out. Basically I have to use too many quotations in my selenium command, and they conflict with each other. What is the proper way to write the following command, the quotation marks keep interacting with each other in ways I do not intend.

The error happens around the quotation in

[@value='E-mail

driver.executeScript("document.getElementByXpath('//UIAApplication[1]//UIATextField[@value='E-mail address']').setAttribute('value', 'example')");
mattman88
  • 475
  • 1
  • 8
  • 22
  • possible duplicate of [In Java, is there a way to write a string literal without having to escape quotes?](http://stackoverflow.com/questions/3034186/in-java-is-there-a-way-to-write-a-string-literal-without-having-to-escape-quote) – SiKing Aug 04 '15 at 20:01

1 Answers1

2

It may be simpler to break up what you want inside driver.executeScript. Maybe try:

documentXpath = "'//UIAApplication[1]//UIATextField[@value='E-mail address']'"

documentget = document.getElementByXpath(documentXpath).setAttribute('value', 'example')

driver.executeScript(documentget)

Or some variant of the above!

Athan Small
  • 58
  • 11
  • Thanks, this looks promising. Two questions: 1. what type of variables should documentXpath and documentget be? Strings? 2. why is the word "document" in document.getElementByXpath causing an error in my code? Any ideas? Thanks! – mattman88 Aug 04 '15 at 21:47
  • Those two questions may have to do with what language you're using for syntax purposes. However, make sure that the variable you have set for the webdriver is the one that comes before the ".". For example, driver.find_element_by_id() *within Python. That may go beyond the original scope of this specific question, though. If I helped you with the quotations, would you mind accepting my answer? – Athan Small Aug 04 '15 at 21:52
  • Thanks, I'm using Java. I will give that a try – mattman88 Aug 04 '15 at 21:55