Search code examples
seleniumweb-scrapingscrapy

Selenium click on already known element stored in variable


I'm use Scrapy and Selenium. After scrapy do some work I have click-able element stored in variable so I think that driver.find_element_by is not necessary because element is already known. So I was hope that something like this exist:

my_variable = '<input type="submit" value="...">'
button = driver.element(my_variable)
button.click()

But 'WebDriver' object has no attribute 'element' So it there a way to use variable instead find_element_by?


Solution

  • I'm not familiar with Scrapy, but the click() function is WebElement functionality. driver.find_element_by returns WebElement, so you can do something like that:

    button = driver.find_element_by()
    button.click()
    

    So in your case you can do

    my_variable.click()