显示以下错误:
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")
答案 0 :(得分:1)
正如@Guy所指出的,您有一个SyntaxError
,XPath的id
是定位符中的字符串,''
现在的XPath应该类似于:>
By.xpath("//*[@id='center_column']/div[1]")
不是
By.xpath("//*[@id='center_column]'/div[1]")