SyntaxError: invalid syntax error using xpath with Selenium and Python

SyntaxError: invalid syntax error using xpath with Selenium and Python

我正在编写一个简单的代码,我需要在其中提取 html 标签的内容,该标签是 <span>。我已经使用 xpath 来做到这一点。 这是错误

File "C:\Users\BRS\Desktop\AccountChef\wattpad acc maker - Copy.py", line 41
    emailentry = wd.findElement(By.xpath(//*[@id='email']//span)).getText();
                                         ^
SyntaxError: invalid syntax

既然是语法错误,我想我不需要给出完整的代码。 请告诉我做错了什么

似乎混淆了 's and 语言绑定语法。

  • 如果您正在使用 Python 您需要使用 find_element_by_xpath()text属性如下:

    emailentry = wd.find_element_by_xpath("//*[@id='email']//span").text
    
  • 如果你使用Java你需要使用findElement()getText()方法如下:

    String emailentry = wd.findElement(By.xpath("//*[@id='email']//span")).getText();