CSS selector of 'compose' button in Gmail invalid when used as selector in Puppeteer

javascript css puppeteer

85 观看


35 作者的声誉

Right now I am trying to write a script which sends email automatically. I am using Puppeteer. In the process of sending an email from gmail I have to click on the 'compose' button obviously. So right clicked on that button and clicked on the inspect option. Afterwards I copied the selector of this element (you can do this by right clicking the part of the code that appears and click copy>copy selector). The selector is #\3a 4e > div > div. Then I copied this in my script and tried to run it, but I got an error :

'#a 4e > div > div' is not a valid selector.

What seems weird to me is that the \3 has disappeared.

I dont understand why it is not a valid selector. I have been using puppeteer using other websites and there I did the same procedure of copying the selector and using that in the script. Somehow in this case it doesn't work. I have to note that I am new to this business.

作者: etotheipi 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


1631 作者的声誉

Since the selector itself contains a backslash, you need to escape it (with another backslash) if you include it in a JavaScript string literal:

var selector = '#\\3a 4e > div > div'
作者: Pasi 发布者: 30.12.2017 12:37