I have been playing roblox a lot lately, and I was wondering if there was a way to automate the login process since I play on different computers each time. I looked into Python's selenium, and derived the script:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.roblox.com/login")
usernameStr = '<redacted>'
passwordStr = '<redacted>'
username = driver.find_element_by_id('login-username')
username.send_keys(usernameStr)
password = driver.find_element_by_id('login-password')
password.send_keys(passwordStr)
signInButton = driver.find_element_by_id('login-button')
signInButton.click()
When I run it in VScode it works perfectly, but when I exported the python file and tried running it via interpreter, it gave many errors around version types. I installed selenium on the computer as well. My hypothesis is my local computer had some tools in the background that when I tried on other computers didn't. Is there something that I am missing when going to my other computer? I am using python3.8.
One thing you could is make a script, when executed runs by the python in your $PATH.
#!/usr/bin/env python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.roblox.com/login")
usernameStr = '<redacted>'
passwordStr = '<redacted>'
username = driver.find_element_by_id('login-username')
username.send_keys(usernameStr)
password = driver.find_element_by_id('login-password')
password.send_keys(passwordStr)
signInButton = driver.find_element_by_id('login-button')
signInButton.click()
If you save this file in your terminal and run chmod +x <filename> to give it executable permissions, it will be a executable, which you can move from machines. Make sure to have all other selenium dependencies installed as well. When working with selenium, make sure your chrome driver is the same as your chrome browser, which you can read about on the chrome webdriver page.
Related
After a few days of searching and experimenting with any of the solutions I could find online, I give up and want to get some help from the community.
Ruby gems (ruby 2.5.1):
watir 6.11.0
selenium-webdriver 3.4.1
Docker:
selenium/node-chrome-debug:3.14
selenium/hub:3.14
My ruby code:
prefs = {
download: {
prompt_for_download: false,
default_directory: download_directory
}
}
browser = Watir::Browser.new(:chrome, url: selenium_hub_url, options: {prefs: prefs})
Our set-up is:
Run a selenium/hub and a selenium/node-chrome-debug. Something that might be different is that we are mounting the /tmp of the base OS as /hosttmp/tmp in the node container
Make the selenium/node-chrome-debug talk to selenium/hub
Make the browser automation talk to the selenium/hub using the code provided above
The problem is that I was never able to set the default download directory. However, all other parts are working correctly. The VNC window shows the browser is working correctly despite the default download directory settings. It is always /home/seluser/Downloads
Things I have tried:
Other people's ideas such as different ways to specify the options and preferences. (e.g. using the Capabilities)
Docker security-related settings such as: --privileged --security-opt apparmor:unconfined --cap-add SYS_ADMIN
On the base OS, chmod 777 for the download_directory. The download_directory, for example, /tmp/tmp.123 on the base OS, which is mounted as /hosttmp/tmp/tmp.123 in the chrome node container, I could see it and make a few read/write operations in this folder inside the container or on the base OS
Tweaks about the interesting ruby symbol/string stuff when creating a Hash object.
Does anyone have more ideas about what could lead to this situation? What else I could try? And is there any log that I could refer to. There is no error or warning when running the code. Thanks in advance.
I'm using Java+Docker+Selenium+Chrome for automation test and also met similar issue with you. Please find my solutions below and try if it works for your case.
Don't set default download directory in the options, just leave "/home/seluser/Downloads" as it is.
When you start up the chrome node on docker, please add the parameter of volume that could transfer the downloaded files to the directory you want.
e.g. docker run -d -p 5900:5900 --link myhub:hub -v :/home/seluser/Downloads selenium/node-chrome-debug:3.14.0
In my case, the JDK environment and my test script is on Linux machine while the selenium webdriver & browser are all on docker, so once the file downloaded by browser it cannot saved directly on Linux machine, you have to mount the local directory with default directory on docker. Then you could find the file saved in the directory you want.
Thanks & Regards!
Jing
Did you define options = Selenium::WebDriver::Chrome::Options.new?
We use
options = Selenium::WebDriver::Chrome::Options.new
prefs = {
prompt_for_download: false,
default_directory: download_directory
}
options.add_preference(download: prefs)
and then you would want something like
browser = Watir::Browser.new(:chrome, url: selenium_hub_url, options: options)
But maybe the main problem is just that you are using
options: {prefs: prefs}
instead of
options: {download: prefs}
Okay, by digging into the source code of the Watir and Selenium-Webdriver, I think I know the 'root cause'.
I have created an issue since I am not sure if this is a bug or a 'feature' The issue
Also, I have a workaround for my case, in watir/capabilities.rb:
Change
#selenium_browser = browser == :remote || options[:url] ? :remote : browser
to
#selenium_browser = browser == :remote ? :remote : browser
This shouldn't be the final solution as it might not be a good idea. Will wait for what the Watir people say about this.
I wrote a few tests with casperjs. They run just fine with phantomjs. However, when I tried to use slimerjs with the following command:
casperjs --verbose --engine=slimerjs test create-project-suite.js
A small window appers with the SlimerJs logo and version number but the console seems to hang with the following line:
Test file: create-project-suite.js
Is there anything else I need to do? Here are the version numbers:
Mozilla Firefox 28.0
CasperJS version 1.1.0-beta3
Innophi SlimerJS 0.9.1
3.8.0-37-generic #53~precise1-Ubuntu
Update:
I removed code until I got slimerjs to open the browser and execute tests. It seems that it hangs whenever I require a js file (I'm following the page objects pattern):
var Login = require('./objects/login');
I think require.paths could be helpful. Any ideas on how to get around this?
Using full paths makes slimerjs happy:
var path = fs.absolute(fs.workingDirectory + '/objects/login');
var Login = require(path);
It is plain simpler to move all modules to the same directory where the script is.
I tried your command and it works for me, maybe in your file you use an instruction specific to phantom :
http://docs.slimerjs.org/0.8/differences-with-phantomjs.html
But it should open the window(at least the start() ).
Anyway the command is fine.
I have written my script specifically for FF. Now I wish to run that same script on Chrome as well as IE. Also I want to run my tests in following order :
Open browser1.
Run script on that browser.
Close browser1.
Open browser2.
Run script on that browser.
Close browser2.
Please help.
In order to run your tests on :
1.Chrome : you will need to install latest Chrome driver, unzip it and paste its path in the environment variables.
2.IE : you will need to install IEDriver server unzip it and paste its path in the environment variables and enable protected mode for each zone in following way (Internet options->security tab->enable protected mode checkbox).
For running your tests as per the way you mentioned, not sure what framework you're using or whatever, but you can do this with a loop. You can do the following :
def all_browsers
browsers = [:firefox,:chrome,:ie].each do |br|
$driver = Selenium::WebDriver.for br
$driver.manage.window.maximize
$driver.navigate.to("http://google.com")
end
$driver.quit
end
We are currently working on an web application testing using Selenium-Webdriver with Ruby. Originally we only test the OSX platform, until recently we realize that Windows platform should also be tested, (IE, Firefox, Chrome, Opera). But those following lines code that work well on OSX fails on Windows(7 & 8).
I want to upload a zip file from relative directory on Windows, like "./assets/application/www.zip"
#driver.execute_script("arguments[0].style.visibility = 'visible'; arguments[0].style.width = '1px';arguments[0].style.height = '1px';arguments[0].style.opacity = 1",upload_a_zip_btn)
upload_a_zip_btn.send_keys (File.expand_path("../../assets/application/www.zip",__FILE__)) # 1
upload_a_zip_btn.send_keys ("assets\/application\/www.zip") # 2
upload_a_zip_btn.send_keys "C:\\www.zip" # 3
I tried all the 3 conditions, but only the 3rd works.
The error appeared in Browser said some error like "no attached file"
Does anyone know how to deal with such situation? Thanks
I followed the docs and wrote:
require 'rubygems'
require 'appscript'
loginKeychain = Appscript::app('Keychain Scripting').keychains['login.keychain']
userName = loginKeychain.keys[its.name.eq(name)].password.get
UPDATE: if I run the script via Terminal, it succeeds the first time, and then returns the error below until I quit and restart Terminal; and repeat...
Error returned intermittently:
/Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.3/lib/appscript.rb:539:in `_send_command': CommandError (Appscript::CommandError)
OSERROR: -600
MESSAGE: Application isn't running.
COMMAND: app("/System/Library/ScriptingAdditions/Keychain Scripting.app").keychains["login.keychain"].keys[its.name.eq("a name")].password.get()
UPDATE 2: Due to the mysterious error, and that Keychain Scripting seems buggy in general, I decided to use MacRuby. I found the MacRuby Keychain Wrapper library, which calls Keychain Services directly, rather than going through Scripting:
require 'keychain-wrapper/keychain'
MRKeychain::GenericItem.item_for_service(service_name).password
Easy
More efficient
Works flawlessly
Done.
I didn't use Ruby but I used Python and I have no trouble. I'd try doing regular Applescript and seeing if it can access Keychain Scripting. If not then try rebooting your Mac. But this sounds like more a problem of your computer than Appscript.
I'm getting that same error, but just with things that require authentification:
kc = app("Keychain Scripting").keychains["login.keychain"]
p kc.keys[its.name.eq("loginwindow")].name.get
# ["loginwindow"]
p kc.keys[its.name.eq("loginwindow")].password.get
# ... Application isn't running ...
tell app "Keychain Scripting" to password of keys of keychain "login.keychain" where name is "loginwindow" works just fine.