Reputation: 95
I'm trying to use selenium to invoke my webpage as googlebot. below is my code, but it does redirect the traffic to view webpage as googlebot...Can someone help me to direct my requests to googlebot programmatically?
package com.eviltester.captureNetworkTraffic;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
public class SeleniumTrafficAnalyserExampleTest {
@Test
public void testProfileEvilTester() throws Exception{
// Start the Selenium Server
SeleniumServer srvr = new SeleniumServer();
srvr.start();
// Create a Selenium Session with captureNetworkTraffic ready
String site = "...";//My URL
DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*iexplore", site);
selenium.start("addCustomRequestHeader=true");
selenium.addCustomRequestHeader("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
// open a page to get the traffic
selenium.open("/us/en_us/");
selenium.close();
selenium.stop();
srvr.stop();
}
Upvotes: 2
Views: 1871
Reputation: 95
Below code works as expected
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "Googlebot/2.1+http://www.googlebot.com/bot.html)");
WebDriver driver = new FirefoxDriver(profile);
String site = "http://store.nike.com/us/en_us/";
driver.get(site);
Upvotes: 0