HTTP Basic Auth via URL in Firefox does not work?

后端 未结 8 2135
悲&欢浪女
悲&欢浪女 2020-11-30 02:18

I know that normally you can login to sites that require HTTP basic authentication with Selenium by passing the username and password in the URL, e.g.:

sele         


        
8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 02:36

    Well, you can make you use of the Sikuli script to handle this Firefox Authentication popup in Windows as well as in Linux environment.

    • Download and Setup Sikuli in Windows/Linux(Need to install dependencies)
    • Use the following Sikuli Script to handle popup: where Authentilcat1.png is the popup image and it will handle 100 popups

    for i in range (100): while exists(Pattern("Authentlcatl.png").similar(0.99)): print("Found Authentication Popup") wait(2) type("admin" + Key.TAB) type("admin" + Key.ENTER)

    • Use the following code to trigger and terminate the Sikuli script from Java code:

    To Trigger the Sikuli Script:

    String[] lincmd = { "bash", "-c", "sudo java -jar Sikuli-X/Sikuli-IDE/sikuli-script.jar Sikuli-X/Sikuli-IDE/new1.sikuli/" };
    

    java.lang.Runtime.getRuntime().exec(lincmd);

    To Terminate the Sikuli Script:

    String[] lincmd = { "bash", "-c", "sudo kill $(ps aux | grep '[s]ikuli' | awk '{print $2}')" };
    

    java.lang.Runtime.getRuntime().exec(lincmd);

    • After triggering the Sikuli script from Java code,Sikuli script will run as another process separately,so finally in the Java code terminating the Sikuli script.

    • So whenever the popup appears in the screen,Sikuli script will handle.

提交回复
热议问题