Selenium has a nice support for "accept cookies" popups
Few days ago, I wrote some simple project using Selenium. More than a year passed from time, when I worked with this library. I was really nice surprised with new features provided by Selenium.
Let’s see a simple example of application which checks Oracle critical patch updates. Firstly, we need to define our method which will search for patches from selected period:
In first step we open page with url passed by constructor, then we wait for page being loaded. After page loaded we expect accept cookies frame which we have to accept. Then we can search for interesting patches.
Let’s see waitForPageLoad implementation:
But for me, the most interesting part is defined in acceptCookiesPolicy method:
As we see, after accept cookies button click we can simply switch to default content and Selenium will now operate on the main document. Is that so simple? :)
Now we can search for interesting patch updates:
In this method we load all rows from table containing rows with patch updates. We skip a first row, which contains column titles. Then we can parse date from second column and check if it is between interested time period.
In my opinion, after almost 2 years selenium API became more friendly for developers. It has also great community support with lot of StackOverflow questions.
You can find the source code in my Github repository how-to under a selenium-cookies directory.
Hope you enjoy this post. If You have any questions or problems leave a comment or send email.
See You soon!