-
Notifications
You must be signed in to change notification settings - Fork 337
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
Chrome - Link('<link_text>') works in non-headless mode, but doesn't work in headless mode #47
Comments
I encountered the same issue, in headless mode helium fails to identify elements. |
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:
# 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. |
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 |
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:
Look forward to a proper solution so that I can eventually remove this nasty hack! |
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'])
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
In terms of the solution, is |
I'm using
start_chrome()
on macOS, Google Chrome, chromedriver and helium are upgraded to the latest (stable) versions.I have a script with a line
to click on a hyperlink on a web page, which works perfectly except when
headless=True
is passed tostart_chrome()
.I'm not very familiar with the underlying selenium-python framework, so I'm not sure if I ask this question in the right issue tracker. :(
Is this a known problem of helium? Is there any way to make helium work with headless Chrome? Thanks!
Versions:
The text was updated successfully, but these errors were encountered: