M
M
mihsaklimov2019-07-13 21:13:47
Java
mihsaklimov, 2019-07-13 21:13:47

How to use AsyncTask along with Selenium?

With Selenium automation, I need to find an object on a page.
I'm looking for id. Throws an exception

Caused by: org.openqa.selenium.NoSuchElementException: Could not find element with id: search-text

Also in the post I read that you need to transfer the network to another thread, but I already used AsyncTask.E/NetworkUtilities: [MTK_net]ss.ss_family:2
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MyAsyncTask myAsyncTask = new MyAsyncTask();
        myAsyncTask.execute(this);
    }

    class MyAsyncTask extends AsyncTask<Activity, Integer, Integer> {
        @Override
        protected Integer doInBackground(Activity... strings) {
            WebDriver driver = new AndroidWebDriver(strings[0]);
            driver.get("https://rutracker.appspot.com/forum/index.php");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            WebElement element = driver.findElement(By.id("search-text"));
            element.sendKeys("гладиолус");
            element.submit();
                return null;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2019-07-15
@TheKnight

But this does not change the fact that you started to translate the topic. The task of the community is to try to help me, and not to reproach and ask questions that are not related to the topic.

mihsaklimov , the community does not have such a task. There is a task to satisfy your curiosity and scratch your CSF.
If you think otherwise, then you should check your views on reality.
As for your problem - it seems that you made a trivial mistake with the element id. I am observing id "search-text-guest". Also, it's worth thinking about a more sane way of waiting than by pens through Thread.sleep every time.
And yet, let's continue scratching the CSF - using selenium from inside the application to search for something on a third-party site is a bad idea. Why not take advantage of the existing API? If it doesn't exist, why not file it down? What task are you trying to solve at all, that such a perversion was required?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question