Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

I am still learning and in response to one of my questions where I was told that it might be because the element in question is not in view.

I looked through the documentation and SO, here was the most relevant answer: her

You can use the "org.openqa.selenium.interactions.Actions" class to move to an element:

WebElement element = driver.findElement("my-id"));

Actions actions = new Actions(driver);




When I try to use the above to scroll to the element: It says WebElement not defined.

I think this is because I have not imported the relevant module. Can someone point out what I am supposed to import?

But in the meantime right after trying to figure it out for some time. I have found out the import method for WebElement:

from selenium.webdriver.remote.webelement import WebElement

Might help someone like me.

The how of it is also a good lesson, IMO:

Went to the Documentation

class selenium.webdriver.remote.webelement.WebElement(parent, id_, w3c=False)

Need to be separated into the command form mentioned above.

1 Answer

0 votes
by (62.9k points)

You are trying to run Java code with Python. In Python/Selenium, the org.openqa.selenium.interactions.Actions are reflected in ActionChains class:

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_id("my-id")

actions = ActionChains(driver)


Or, you can also "scroll into view" via scrollIntoView():

driver.execute_script("arguments[0].scrollIntoView();", element)

To learn in-depth about Selenium, sign up for an industry based Selenium training

If you wish to learn more about Python, visit the Python tutorial and Python Certification course by Intellipaat.

by (100 points)
When i perform the first line (element = driver.find_element_by_id("my-id")), i get "Message: no such element: Unable to locate element: ... " error. This is because the element is visually not on the page. I want to scroll to the particular element, but i run into the error which halts me from moving on...

Any possible fix?

Browse Categories