首页 > 解决方案 > 在 driver.FindElement(By.XPath) 行上获取 cs1010(Newline in constant) 异常

问题描述

反斜杠和撇号都是 XPath 中常用的字符。也许这总是发生,我现在才看到它,因为我在该行中添加了一个手表,但似乎每个 FindElement 行都抛出了这个异常

引发此错误的行之一是...

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

我希望正确的 XPath 语法不会导致异常。

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>

标签: c#seleniumxpath

解决方案


虽然这并没有解决关于 FindElement 语法的最初问题,并且它导致 CS1010: Newline in Constant 异常,但这确实帮助我克服了阻碍我的问题。

谢谢昆都克


推荐阅读