我想使用以下元素查找元素:
self.s2l.execute_javascript(
'document.findElement(By.XPath"{}")[0].scrollBy(0,{})'.format(
element,
new_position
)
错误:
参数列表后的[JavascriptException:消息:javascript错误:缺少]
当我使用时:
self.s2l.execute_javascript(
'document.getElementsByClassName("{}")[0].scrollBy(0,{})'.format(
element,
new_position
)
Works and test pass.
您能不能帮Xpath毁了什么?
您需要在By.XXX()
的参数周围加上括号。另外,在.
和定位符的类型之间有一个By
。
self.s2l.execute_javascript(
'document.findElement(By.xpath("{}"))[0].scrollBy(0,{})'.format(
element,
new_position
)
此外,xpath
在JavaScript Selenium中为小写。