简体   繁体   中英

How to nest these quotes?

I am trying to get the following code to work using nested quotes but I don't know how to triple nest them. Here's the code I have so far but it isn't working, I get Runtime.evaluate threw exception: SyntaxError: Unexpected token & when I run it.

driver.executeScript("$("li[data-drilldown='interests']").click()")

It seems like there should be a better way to do this but I'm not familiar enough with Javascript

逃脱它们:

driver.executeScript("$(\"li[data-drilldown='interests']\").click()");

Remove the quotes in the selector as they aren't necessary when the value you are looking for doesn't contain spaces:

driver.executeScript('$("li[data-drilldown=interests]").click()')

or

driver.executeScript("$('li[data-drilldown=interests]').click()")

Because JavaScript allows the single (') or double (") quote as a string delimiter. As long as you have them in pairs that match, either can be nested inside the other. The only exception to this rule is with JSON. There, you must use double quotes to delimit your property names and your string literals.

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