1

So there is a website in which when we enter a character in the 'username' place holder, a captacha appears which I want to use it in my app.

I tried using selenium's ChromeDriver but it gave me the follwing error: "Unable to find a free port". Is there way to change the port for ChromeDriver?

Then I thought I could do the same in JS and call it form Java using Rhino. But I could not find decent tutorial for JS web driver(for the task which I want to perform) or may be I missed out.

MainActivity.java:

 @Override
protected void onResume(){
    super.onResume();
    new MyBackgroundDriver().execute("https://www.google.com/");//for test lets consider google.com
}

class MyBackgroundDriver extends AsyncTask<String, Void, Void> {

    @Override
    protected Void doInBackground(String... url) {
        WebDriver driver=new ChromeDriver();
        driver.get(url[0]);
        driver.quit();
        return null;
    }
}

app/build.gradle:

apply plugin: 'com.android.application'

android {

    compileSdkVersion 28

    packagingOptions {

        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        .....
    }
}

.....

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'

    implementation 'org.seleniumhq.selenium:selenium-java:2.46.0'

    implementation 'junit:junit:4.12'

    //implementation 'io.appium:java-client:3.0.0'

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'

    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Please help me out with this error or provide a solution for getting the generated captcha(without using WebView as I want the UI to be different). So even if there is a way to somehow change the UI(may be by hiding webview or running it in background), you are most welcomed.

Zoe
  • 23,712
  • 16
  • 99
  • 132
yash javeri
  • 347
  • 1
  • 4
  • 15
  • Additionally, please don't tag with [javascript] when you're using Java - they're two very different languages. And please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) – Zoe Jun 12 '19 at 14:08
  • Possible duplicate of [How do you set the port for ChromeDriver in Selenium?](https://stackoverflow.com/questions/38270270/how-do-you-set-the-port-for-chromedriver-in-selenium) – Greg Burghardt Jun 12 '19 at 18:12
  • While the possible duplicate refers to C#, the Java API should basically be the same. The port number should be a config option. – Greg Burghardt Jun 12 '19 at 18:15

0 Answers0