Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch "click not possible" #19

Open
johny322 opened this issue May 19, 2022 · 3 comments
Open

Catch "click not possible" #19

johny322 opened this issue May 19, 2022 · 3 comments

Comments

@johny322
Copy link

Hi.
Is it possible to catch "click not possible, out of viewport" when using the move_to_element action?
Action move_to_element_outside_viewport does not work for me, because the element with scrolling is inside another webelement.

@droefs
Copy link
Owner

droefs commented May 23, 2022

Is it possible to catch "click not possible, out of viewport" when using the move_to_element action?

Yes, this should do it:

    from HLISA.errors import OutOfViewportException
    from HLISA.hlisa_action_chains import HLISA_ActionChains
    actions = HLISA_ActionChains(driver)
    try:
        actions.move_to_element(element).click().perform()
    except OutOfViewportException:
        print("catching click not possible, out of viewport")

Action move_to_element_outside_viewport does not work for me, because the element with scrolling is inside another webelement.

This is interesting. Do I understand correctly that there is an element in the viewport, which you need to scroll in, and only after scrolling this element, the element you want to click on shows up?

@johny322
Copy link
Author

johny322 commented May 23, 2022

Thank you for your answer.

This is interesting. Do I understand correctly that there is an element in the viewport, which you need to scroll in, and only after scrolling this element, the element you want to click on shows up?
Yes, it is.

@droefs
Copy link
Owner

droefs commented Jul 23, 2022

Due to time constraints I will for now not make a function that performs exactly the task you want to do. But I added the possibility to specify an element in the scroll_by(), which makes it possible to scroll human like in an element.

You can use actions.move_to_element_outside_viewport(element_to_scroll_in) to scroll to the element you need to scroll in, and then use actions.scroll_by(0, y, True, element_to_scroll_in) to scroll in that element with y pixels. This makes it possible to perform your task in a human like manner, but y still needs to be calculated manually and hardcoded.

Example:

driver.get("https://stackoverflow.com/questions/15182496/why-does-this-code-using-random-strings-print-hello-world?noredirect=1&lq=1")
time.sleep(5)
element_to_scroll_in = driver.find_element(By.XPATH, "/html/body/div[3]/div[2]/div/div[1]/div[3]/div[3]/div[5]/div/div[2]/div[1]/pre[1]")
actions.move_to_element_outside_viewport(element_to_scroll_in)
actions.scroll_by(0, 300, element=element_to_scroll_in)
actions.perform()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants