我使用Scrapy和Selenium。在scrapy做了一些工作后,我有可存储在变量中的可点击元素,所以我认为driver.find_element_by
不是必需的,因为元素已经知道了。所以我希望存在这样的事情:
my_variable = '<input type="submit" value="...">'
button = driver.element(my_variable)
button.click()
但是'WebDriver' object has no attribute 'element'
所以有一种方法可以使用变量而不是find_element_by
?
答案 0 :(得分:0)
我不熟悉Scrapy,但click()
函数是WebElement
功能。 driver.find_element_by
会返回WebElement
,因此您可以执行以下操作:
WebElement button = driver.find_element_by()
button.click()
所以在你的情况下你可以做到
my_variable.click()