简体   繁体   中英

getting cs1010(Newline in constant) exception on driver.FindElement(By.XPath) lines

Both backslash and apostrophe are common characters used in XPath. Perhaps this always happens, and I only see it now because I added a watch to the line, but it seems every FindElement line is throwing this exception

One of the lines throwing this error is ...

if (loadedPage.FindElements(By.XPath("//div[@class='field signature capture']")).Count != 0)

I expect the proper XPath syntax to not cause an exception.

HTML ...

                    <div class='loaded page' id='page_0' style='height:1030.0px;width:796.0px;background-image:url(/packages/INDle9T1Y4PGRpKDir2KZxuTWoY=/documents/26a85bc2-d735-4135-ad15-d09ce11699f1/pages/0?v=322608);'>
                      <!-- - cssclass  = "field role_#{approval.role.id} #{field.type} #{field.subtype} #{approval.accepted? ? 'accepted' : ''}" -->
                      <div approval='hc1T31A6E0I6' class='field signature capture ' esl_id='_ircL7s98umMX' id='ircL7s98umMX' style='height:55.0px;left:468.0px;top:369.0px;width:220.0px;' tabindex='1' title='Click on the yellow box to capture your handwritten signature.'>
                        <div class='loading'>&nbsp;</div>
                        <div class='required sticky unselectable' role='presentation' style='left:-468.0px;top: 27.5px;'>&nbsp;</div>
                        <div class='content'>
                          <div class='name unselectable'>
                            <div class='cts'>
                              <img class='checkmark' src='/images/ballot_x.png'>
                              Click to Sign
                            </div>
                          </div>
                          <div class='bg required' style='height:53.0px;width:218.0px;'><span class='capture-indicator'></span></div>
                        </div>
                      </div>

To check your Html i can see there is white space at end end of the class attribute.

Instead of this.

if (loadedPage.FindElements(By.XPath("//div[@class='field signature capture']")).Count != 0)

Try this.

if (loadedPage.FindElements(By.XPath("//div[contains(@class,'field signature capture')]")).Count != 0)

OR

if (loadedPage.FindElements(By.XPath("//div[normalize-space(@class)='field signature capture']")).Count != 0)

While this did not address the initial question regarding the syntax of FindElement and it causing the CS1010: Newline in Constant exception, this did help get me past the issue that was blocking me.

Thank you KunduK

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