Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97788

Can you bypass a 403 code in Selenium WebDriver using cookies?

$
0
0

I'm accessing a url string via the src attribute of an img Html element using WebDriver. However, when i try to open a new window to that URL i get a 403 Unauthorized access and i don't know how to overcome it. I've read many posts here on stackoverflow but the most promising solution i saw, was to specify a User agent preference in a URLConnection, but to no avail. Here's my code so far :

WebDriver driver = new ChromeDriver();            
        String urlSelector = "body > div.overlay > div#cards"+cardID + "> div.one.card > img.core.load.bg.on";
        WebElement urlElem = driver.findElement(By.cssSelector(urlSelector));
        String url = urlElem.getAttribute("src");
        driver.get(url);

EDIT: I read on another post that i may need to pass certain cookies to the URLConnection in order to avoid the 403 response code and to authenticate myself. So i checked the cookies that are present when i am on the website (using the WebDriver) and the results are shown below:

cookies_one

cookies_two

However, if i open the same website on a normal browser (not using WebDriver) , i get some extraimgur cookies which are list below :

cookies_threecookies_four

Imgur is what the site is using to display the images when i click on their links as far as i understand. I also decided to check the cookies on imgur after clicking on the image's link in a normal browser and i got 2 which seem to be related to a database(?) :

cookies_five

Is any of these cookies as far as you can tell used to authenticate me and is there a way to use those in my URLConnection to avoid the 403 response code?

P.S: Website in question is this website


Viewing all articles
Browse latest Browse all 97788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>