尝试使用xpath时出错

时间:2019-03-28 07:52:11

标签: selenium selenium-webdriver

显示以下错误:

invalid selector: Unable to locate an element with the xpath expression //*[@id='center_column]'/div[1] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@id='center_column]'/div[1]' is not a valid XPath expression.

代码试用:

driver.findElement(By.xpath("//*[@id='center_column]'/div[1]")).getCssValue("background-color")

1 个答案:

答案 0 :(得分:1)

正如@Guy所指出的,您有一个SyntaxError,XPath的id是定位符中的字符串,''现在的XPath应该类似于:

By.xpath("//*[@id='center_column']/div[1]")

不是

By.xpath("//*[@id='center_column]'/div[1]")