Monday, April 15, 2024

Selenium on nethunter (pixel)

Make sure firefox is installed

$ firefox -V
Mozilla Firefox 115.5.0esr

Download geckodriver

$ wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux-aarch64.tar.gz
$ tar xzvf geckodriver-v0.34.0-linux-aarch64.tar.gz

After this step "geckodriver" should be there

$ ./geckodriver -V
geckodriver 0.34.0 (c44f0d09630a 2024-01-02 15:36 +0000)
The source code of this program is available from testing/geckodriver in https://hg.mozilla.org/mozilla-central.
This program is subject to the terms of the Mozilla Public License 2.0. You can obtain a copy of the license
at https://mozilla.org/MPL/2.0/

Install 'selenium'

$ pip3 install selenium

Test code

import os
import sys
import logging
from selenium import webdriver
from selenium.webdriver.firefox.service import Service


THIS_DIR = os.path.dirname(os.path.abspath(__file__))
DRIVER = os.path.join(THIS_DIR, "geckodriver-v0.34.0-linux-aarch64", "geckodriver")

if not os.path.exists(DRIVER):
    print("Cannot find 'geckodriver'")
    sys.exit(1)


def main():
    print("Downloading web page...")

    s = Service(executable_path=DRIVER)

    options = webdriver.FirefoxOptions()
    options.add_argument("--headless")

    driver = webdriver.Firefox(service=s, options=options)
    
    driver.get("https://www.google.com")
    driver.save_screenshot("screenshot.png")

    print("Please check screenshot image")
    driver.quit()


if __name__ == '__main__':
    main()

After run this code "screenshot.png" should be generated

To show "screenshot.png" image in RLogin

$ sudo apt install libsixel-bin
$ img2sixel screenshot.png

Done.

No comments: