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

send_keys doesn't work for key combinations in geckodriver 0.19.1 + FF 57.0 #1075

Closed
FzmTYustas opened this issue Nov 24, 2017 · 21 comments
Closed

Comments

@FzmTYustas
Copy link

System

  • Version: 0.19.1
  • Platform: Win7x64 SP1 Ent
  • Firefox: 57.0
  • Selenium: 3.7.0

Testcase

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait

binary = FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe")
driver = webdriver.Firefox(firefox_binary=binary)

driver_wait = WebDriverWait(driver, 4)

el = driver_wait.until(ec.presence_of_element_located((By.TAG_NAME, 'body')))
el.send_keys(Keys.CONTROL + 't')

As a result, new tab is not opened.

@whimboo
Copy link
Collaborator

whimboo commented Nov 27, 2017

You cannot use Ctrl + T to open a new tab, because this is a reserved shortcut and only accessible by Firefox chrome itself. Web content cannot use that. Please see issue #786 which this is a dupe of.

@sivask444
Copy link

findETCElement("name", webLocatorString).sendKeys(Keys.chord(Keys.CONTROL, "a"),Keys.DELETE, inputValueAndQuery);

is not working with firefox 57, Version: 0.19.1.
could u tell me the solution for this one

@wangjunmei
Copy link

action.sendKeys(Keys.chord(Keys.CONTROL, "a")).build().perform();

is not working with firefox 56\chrome 63\geckodriver 0.20 \chromedriver 2.36\selenium 3.8.1
Answer the answer

@FzmTYustas
Copy link
Author

FzmTYustas commented Mar 23, 2018

Now I use execute_script("window.open();") in my tests and this works for me.

@tpangburn
Copy link

tpangburn commented Aug 1, 2018

So I had a script that I used cntl-'-' to zoom out of the window. Now after upgrading I find out it doesn't work anymore. I need it so so I can get my screen captures right size to fit the whole screen. How can I do this now if they don't allow control sequences? I am using geckodriver 0.21.0 and firefox 61.0.1 (64bit)

@andreastt
Copy link
Contributor

Sending keys that affect chrome behaviour is explicitly intended not to work. WebDriver emulates user interactions with the web platform, not with the browser.

@tpangburn
Copy link

OK I guess I don't understand what you mean to say here. I am looking for another way to zoom out of the current window if I can't use the control keys.

@andreastt
Copy link
Contributor

Keys sent via WebDriver is intentionally not meant to have side-effects on the browser UI/chrome since that is outside the scope of the web platform. WebDriver automates and interacts with things that is inside the realm of the document.

You can’t use WebDriver to change the zoom level of a document because that is not a web feature and not something which is implemented similarly across all UAs.

@tpangburn
Copy link

So is there another method to do zooming out? or am I pretty much SOL?

@tpangburn
Copy link

There wouldn't be any browser preferences for instance I could set when I initialize etc?

@tpangburn
Copy link

The reason I really need this control is because I use the scripts to take snapshots of things on a web UI and I want them for logging purposes. However the screen shots get chopped off if I don't have the screen size right.

@andreastt
Copy link
Contributor

In geckodriver you can enter chrome context through the Set Context command to gain access to changing the zoom level, but this won’t be cross-browser compatible.

Zooming out to take a full-document screenshot seems very brittle due to the fact that many modern web apps loading more content as you scroll to edges (such as Twitter). Instead you can use the proprietary geckodriver API to take a full screenshot, or firefox -headless -screenshot PATH.

@tpangburn
Copy link

OK I missed that you replied here as well, but I still not sure how to use the geckodriver API to do it in python. Not sure if I follow what you mean on the firefox -headless option either an how I would put that into the python script or is that someplace else?

@tpangburn
Copy link

tpangburn commented Aug 2, 2018

Well I figured out what I was doing wrong to pass the headless option to firefox. However It looks like it still cuts off the bottom a bit. I like to figure out how to do it with the API command if possible because I sort of like to see what's happening while it is running.

@whimboo
Copy link
Collaborator

whimboo commented Aug 3, 2018

Ok, so here the example with the Python bindings of Selenium. Please note that other bindings might not have added support for set_context()!

from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox(...)
driver.get("https://mozilla.org")
driver.set_context("chrome")
win = driver.find_element_by_tag_name("window")
win.send_keys(Keys.META + "-")

@tpangburn
Copy link

Oh Ok I didn't understand what andreastt was trying to tell me. Having code example makes it much clearer. I not sure if this means I don't have the support for set_context then? I thought I installed selenium onto python, but maybe its not the right version.

driver.set_context("chrome")
AttributeError: 'WebDriver' object has no attribute 'set_context'

@tpangburn
Copy link

well I got it to work but somehow its hanging up when I do a find by css later on that I can't figure out. It seems like if i do the find_element by tag command its screwing things up later on.

@whimboo
Copy link
Collaborator

whimboo commented Aug 8, 2018

You will have to switch back to content after you are done with the chrome scope interaction.

@tpangburn
Copy link

tpangburn commented Aug 8, 2018

Cool thanks that fixed it!! EDIT: By the way I had to change from using the remote webdriver to the direct one as you had in your example. I presume that I can't use the set_context in the remote driver mode.

@tpangburn

This comment has been minimized.

@ghost

This comment has been minimized.

@mozilla mozilla locked as resolved and limited conversation to collaborators Feb 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants