My problem is simple:
I want to do a "select all". This is done differently in macosx compared to linux and windows.
Keys.chord(Keys.COMMAND, "a")
vs
Keys.chord(Keys.CONTROL, "a")
1. sendKeys. Using the Actions class in Selenium, we can implement the sendKeys() method to type specific values in the application.
Now, as we discussed, Selenium WebDriver provides two ways to send any keyboard event to a web element: sendKeys() method of WebElement class. Actions class.
We can also perform a CTRL+A press by simply using the sendKeys() method. We have to pass Keys. CONTROL along with the string A by concatenating with +, as an argument to the method.
In Java, I do little workaround for this:
String os = System.getProperty("os.name");
if (os.equals("WINDOWS")){
Keys.chord(Keys.CONTROL, "a");
}else{
Keys.chord(Keys.COMMAND, "a");
}
Basically - I get the OS where do I run and behave by that accordingly
Since Linux and Windows both support CONTROL, then the only difference would be MAC (Darwin), so I would rather use:
Python:
import platform
os_base = platform.system()
If os_base == 'Darwin':
selector.send_keys(Keys.COMMAND, 'a')
else:
selector.send_keys(Keys.CONTROL, 'a')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With