質問

I've set up a user agent using WebDriver and a FireFox Driver. I have several user agents for different iPhone and android mobile devices that are expected to redirect to a mobile site.

code:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(userAgentOverride, userAgent);
WebDriver driver = new FirefoxDriver(profile);

The following line of code is the syntax I use to navigate to each url (wrapped in a for loop looping through a list of urls)

driver.navigate().to(url);

I loop through a list of urls that will mostly redirect to a mobile site (m.somesite.com), but there are a few that should redirect to the main site. eg. www.somesite.com/full-site redirects to the main site on the mobile device.

My problem is once one of the urls is navigated to that redirects to the main site, the rest of the urls in the list no longer redirect to their mobile link. I've tried removing the urls that redirect to the main page and then all my urls redirect as expected.

Is this a bug or is it expected? I would think that it would allow testing any redirects on an useragent and continue to work, even after a redirect that sends it to the main site.

役に立ちましたか?

解決

The first suspect that comes to mind are cookies. The site tries to be smart, stores a cookie with your setting (that you have a mobile device, but want to see a full site) and the second time you visit the page, it just takes the setting from that cookie and deosn't bother to check again.

Try driver.manage().deleteAllCookies() after navigating to a page, that should get rid of all the stored cookies.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top