简体   繁体   中英

Missing error after argument list - Selenium Python (executing Javascript)

I've been at this for a while now, I know there are some questions along the lines of this one but I cannot figure out where on earth my string isn't escaped correctly or needs more quotes.

I have this line

self.driver.execute_script("$x('//div[text()=\'Find Artwork\']')[0].click()")

and this works perfectly in the console

$x('//div[text()=\'Find Artwork\']')[0].click()

However when running in Python with Selenium + Chrome webdriver I get this error

selenium.common.exceptions.JavascriptException: Message: javascript error: missing ) after argument list

Unsure quite what to do here. I've tried double quotes, escaping, everything.

Thanks!

$x is not part of JavaScript, but just a utility in cosole of firefox and chrome.

See this question .

You can try something like this:

javaScript = "document.getElementsById('username')[0].click();"
driver.execute_script(javaScript)

//or

driver.execute_script("arguments[0].click()", element);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM