termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

termux selenium-webdriver

Open delmarocks opened this issue 7 years ago • 52 comments

delmarocks avatar Feb 15 '18 15:02 delmarocks

Is there any way to run webdriver in termux when automating browsers using python in termux?

delmarocks avatar Feb 15 '18 15:02 delmarocks

I am also curious about this

Hax4us avatar Mar 17 '18 04:03 Hax4us

Selenium is written in java so it's portable, I think it would work

Serkan-devel avatar Jun 02 '18 07:06 Serkan-devel

would be great if termux can run a headless browser like phantomjs to be used in python

delmarocks avatar Sep 11 '18 18:09 delmarocks

Why not hook it to a native browser app? I think that would require adb enabled and phantomjs has been discontinued

Serkan-devel avatar Sep 11 '18 18:09 Serkan-devel

Or one can create a headless chrome package compiled to arm

Serkan-devel avatar Sep 11 '18 18:09 Serkan-devel

so it is possible to use selenium on termux ? if no witch alternatif can help to automatise browser in termux

ambroisehdn avatar Jan 21 '19 09:01 ambroisehdn

So anyone got anything?

SwapnilSoni1999 avatar Aug 11 '19 09:08 SwapnilSoni1999

package request tag is added So will you work on this? @xeffyr

SwapnilSoni1999 avatar May 18 '20 07:05 SwapnilSoni1999

So will you work on this?

Does someone have submitted a pull request with build script and patches for Chromium or Firefox ? Seems no. Adding Selenium webdriver will be useless in such case.

Tag "help wanted" should clearly describe the status of that issue...

ghost avatar May 18 '20 16:05 ghost

is always error 13 . isue is about permision to execute driver chrome or gecko

AhmadNaruto avatar May 20 '20 03:05 AhmadNaruto

just install ubuntu or any other distro on termux and therein install firefox or chromium and selenium Succesfully tested. However google chrome does not work on mobile platform as its not open source and there is no arm version of google chrome while chromium and firefox works successfully.

For chromium Specific settings needed

  1. --no-sandbox arguments needs to be supplied in selenium when using interactive or python script as root user.
  2. binary path to be setted to path of chromium because selenium is made to use google chrome and not chromium. But webdrivers for chromium and google chrome are same. So selenium needs to be instructed to use chromium and not chrome otherwise it will throw exception error that chrome executable not available or not in path.

eg.

For selenium 3 or less: driver = webdriver.Chrome(executable_path ='usr/bin/chromium')

For latest selenium 4, executable path option is deprecated so use object method as below: from selenium.webdriver.chrome.options import Options op = Options() op.binary_location('/usr/bin/chromium') op.add_argument('--no-sandbox') If you are not having a desktop environment or x windows system use headless op.add_argument('--headless') Finally driver = webdriver.Chrome(options=op)

tathastu871 avatar Jun 13 '20 16:06 tathastu871

@tathastu871 yea, that's work, but we want same in termux itself

kcubeterm avatar Jun 13 '20 16:06 kcubeterm

For using it in termux itself following succesfully tested solution. Connect phone to pc with usb debugging enable adb start-server chromedriver Note down port number from output In python on termux from selenium import webdriver

capabilities = { 'chromeOptions': { 'androidPackage': 'com.android.chrome', } } driver = webdriver.Remote('http://localhost:9515', capabilities) # Specify your port number value driver.get('http://google.com') driver.quit()

tathastu871 avatar Jun 13 '20 16:06 tathastu871

Using a distro on termux will allow for portability for selenium automation however for using it on termux only we need to use adb. In case tried adb over wifi works and does the trick thereby bypassing use of usb

tathastu871 avatar Jun 13 '20 16:06 tathastu871

Final solution is to use remote capabilities where phone to be connected over wan using port forwarding and on pc which is kept running all day long with browser installed and whenever we are away from house or pc and want to use selenium on termux use remote capabilities using port and ip address of device.

Port forwarding required only in case of wan when our pc and phone are on different network.

While on lan and on same wifi no port forwarding require.

tathastu871 avatar Jun 13 '20 16:06 tathastu871

adb, chromedriver or geckodriver, selenium are only needed for automating web on android browsers. Among them adb and selenium are both available as termux binaries without need of computer. The only workaround needed is to get chromedriver recoded to run on termux.

Just as adb and fastboot binaries have been remade for termux if chromedriver is also rewritten and made to work in termux everything will be good.

Then there will be no need to use computer or prooted linux distros, just a termux is sufficient

tathastu871 avatar Oct 09 '20 03:10 tathastu871

This is the termux-packages repository. It's a little helpful to remember this works via proot or tethering, but the issue is around introducing termux packages to provide for systems that aren't tethered and don't have the space for a prooted distro.

xloem avatar Sep 05 '21 10:09 xloem

I also would like to be able to use Selenium with Termux or a similar solution

621625 avatar Nov 04 '21 00:11 621625

@tathastu871 tried doing what you suggested but I always have a chrome driver not in path error, how do I fix this? Thanks

EnricoBDev avatar Jan 18 '22 14:01 EnricoBDev

@tathastu871 tried doing what you suggested but I always have a chrome driver not in path error, how do I fix this? Thanks

driver = webdriver.Chrome('/path/to/chromedriver')

tathastu871 avatar Apr 20 '22 01:04 tathastu871

Need help I can't install 'selenium' on termux any solution ????🥺🥺🥺

Thisismo7a avatar Apr 24 '22 07:04 Thisismo7a

Need help I can't install 'selenium' on termux any solution ????🥺🥺🥺

Use andronix app to install ubuntu or any other distro and install chromium or firefox with selenium using apt.

However latest version of firefox may have some problems with selenium. if encountered try downgrading firefox and firefox-geckodriver packages to 75.0+build3-0ubuntu1

incase of chromium extra steps of specifying binary location is required

tathastu871 avatar Apr 25 '22 10:04 tathastu871

Need help I can't install 'selenium' on termux any solution ????🥺🥺🥺

I have written a package like selenium but only need termux to use, no pc require, you can do many simple tasks like login, submit form, .... here is link if you need (i dont know if i can use selenium on android without pc so i made this package)

luanon404 avatar Apr 26 '22 17:04 luanon404

Also theres a package called selendroid. Wonder anyone figured how to use it its a jar binary to control android apps https://github.com/selendroid/selendroid/releases/download/0.17.0/selendroid-standalone-0.17.0-with-dependencies.jar

tathastu871 avatar Apr 27 '22 06:04 tathastu871

Also theres a package called selendroid. Wonder anyone figured how to use it its a jar binary to control android apps https://github.com/selendroid/selendroid/releases/download/0.17.0/selendroid-standalone-0.17.0-with-dependencies.jar

Selendroid. No updates. 4 years.

621625 avatar Apr 27 '22 07:04 621625

Also if adb enabled you can use uiautomator on termux to automate any app including browsers Just enable adb in tcpip mode once using pc.Then no use of pc. Only termux would be sufficient to automate every action on android

Also.on android 11 you dont need pc to enable tcpip adb. Just use wifi setting to do it

So what is the choice for old Android devices and no pc? I've been searching for two years but still can't find an easy way, most need pc or root.

luanon404 avatar Apr 28 '22 04:04 luanon404

just install ubuntu or any other distro on termux and therein install firefox or chromium and selenium Succesfully tested. However google chrome does not work on mobile platform as its not open source and there is no arm version of google chrome while chromium and firefox works successfully.

For chromium Specific settings needed

  1. --no-sandbox arguments needs to be supplied in selenium when using interactive or python script as root user.
  2. binary path to be setted to path of chromium because selenium is made to use google chrome and not chromium. But webdrivers for chromium and google chrome are same. So selenium needs to be instructed to use chromium and not chrome otherwise it will throw exception error that chrome executable not available or not in path.

eg.

For selenium 3 or less: driver = webdriver.Chrome(executable_path ='usr/bin/chromium')

For latest selenium 4, executable path option is deprecated so use object method as below: from selenium.webdriver.chrome.options import Options op = Options() op.binary_location('/usr/bin/chromium') op.add_argument('--no-sandbox') If you are not having a desktop environment or x windows system use headless op.add_argument('--headless') Finally driver = webdriver.Chrome(options=op)

I can't get this to work.. I used Andronix to install Ubunut 20.04 , Desktop Environment LXDE.

Any tips? I keep getting chrome driver not in path error....

DarKnight9023 avatar Aug 16 '22 02:08 DarKnight9023

Now Geckodriver is available for termux. Method1) wget https://github.com/mozilla/geckodriver/releases/download/v0.32.0/geckodriver-v0.32.0-linux-aarch64.tar.gz Method2) cargo install geckodriver

Try enabling: adb start-server --> adb tcpip 5555 then on Termux --> run adb connect localhost:5555 geckodriver it will show port --> Use selenium remote capabilities to connect to localhost:port number and we can control firefox app using selenium directly from termux

Can anyone try it i cant enable adb on my device

tathastu871 avatar Nov 01 '22 07:11 tathastu871

Now Geckodriver is available for termux. Method1) wget https://github.com/mozilla/geckodriver/releases/download/v0.32.0/geckodriver-v0.32.0-linux-aarch64.tar.gz Method2) cargo install geckodriver

Try enabling: adb start-server --> adb tcpip 5555 then on Termux --> run adb connect localhost:5555 geckodriver it will show port --> Use selenium remote capabilities to connect to localhost:port number and we can control firefox app using selenium directly from termux

Can anyone try it i cant enable adb on my device

solution for android 11 above only

luanon404 avatar Nov 01 '22 08:11 luanon404