Giter Club home page Giter Club logo

Comments (6)

danbaghilovici avatar danbaghilovici commented on May 21, 2024 2

This may be a problem with selenium . I remember that they had problems identifying the elements when wrapped around css pseudo selectors. From @ttamg example, the footer navigation links from microsoft seem to be inside an ::after and ::before.
image
I will try to test to see if that's the issue.

from helium.

shravanasati avatar shravanasati commented on May 21, 2024 1

I encountered the same issue, in headless mode helium fails to identify elements.

from helium.

ttamg avatar ttamg commented on May 21, 2024

Hi. Here is code to replicate the same sort of issue. In this case it works for Chrome but not Firefox. I am using Ubuntu 20.04 LTS.

The code below looks for links on the Microsoft home page at the top and bottom of the page:

  • All the objects can be found on the page. The helium.find_all() does find the object. So that's good.
  • The helium.click() does work when the object is on the page but not when it needs to scroll down. I have found this in Chrome headless mode too. The code below raises a Lookup error in Firefox Headless and non-headless modes only.
# Code to replicate the click issue (on Firefox - Ubuntu)
import helium

HEADLESS = False
URL = "https://www.microsoft.com/en-gb"

driver = helium.start_firefox(URL, headless=HEADLESS)
# driver = helium.start_chrome(URL, headless=HEADLESS)

# Object near top of page so does not require any scroll
obj1 = helium.find_all(helium.Link("Deals"))
print(f"Links found on page - {obj1}")
helium.click(obj1[0])
print(f"Link clicked - now on page URL = {driver.current_url}")

# Reset
driver.get(URL)

# Object near foot of the page so requires a scroll down to click
obj2 = helium.find_all(helium.Link("Investors"))
print(f"Links found on page - {obj2}")
helium.click(obj2[0])
print(f"Link clicked - now on page URL = {driver.current_url}")

helium.kill_browser()

When you run this on Firefox we get a lookup error only at the very end when trying to click the link at bottom of the page.

I had a look at the source and the click method does use a scroll to object but for some reason it doesn't work on Firefox. Line 205 in https://github.com/mherrmann/selenium-python-helium/blob/master/helium/_impl/__init__.py.

I was struggling to debug much beyond this but hopefully it helps someone who understands Selenium to dig a bit deeper.

from helium.

myii avatar myii commented on May 21, 2024

Hitting this issue on Firefox as well and groped around for any way to workaround it. This is an ugly hack but it gets the job done both headless or otherwise:

    if use_search_to_scroll:
        press('/')
        write(link_text)
    click(link_text)

Where:

  • use_search_to_scroll is used to run the hack only for the links that may need to be scrolled to.
  • link_text is the link text that needs to be clicked.

Look forward to a proper solution so that I can eventually remove this nasty hack!

from helium.

mherrmann avatar mherrmann commented on May 21, 2024

Look forward to a proper solution so that I can eventually remove this nasty hack!

I am always happy to receive Pull Requests :-)

from helium.

myii avatar myii commented on May 21, 2024

I am always happy to receive Pull Requests :-)

@mherrmann I've found a cleaner workaround, I'm wondering whether it's something that could be used as a solution.

So this instead of the snippet above:

    scroll_down(Link(link_text).web_element.location['y'])
  • Single-liner, no need for the if block.

In fact, because my site has a navigation bar and breadcrumbs, I had to adjust for those (simplifying my own solution a bit):

    scroll_down(Link(link_text).web_element.location['y']) - 100
  • I suppose it would be better to scroll enough so that the link is in the centre of the window but I haven't figured out how to reference the window height yet.
  • Link(link_text) can be adjusted to deal with the type of element that needs to be clicked on, of course.

In terms of the solution, is .web_element.location['y'] reliable enough?

from helium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.