Set User-Agent #
setUserAgent(String userAgent);
Changes User-Agent
header for outgoing requests and navigator.userAgent
.
To resetUser-Agent
to its default value, passnull
as the new value.
SettingUser-Agent
to an empty string will actually update theUser-Agent
to empty string.
public void testUIWithLoadero() {
// Example of setting custom user-agent
// Open page and create screenshot with default User-Agent
open("https://www.google.com/");
E(byCssSelector("[action=\"/search\"]")).waitFor(10).untilIsVisible()
.saveScreenshot("default_user_agent.png");
// Set custom User-Agent value
setUserAgent("Custom User Agent");
// Refresh the page
getSelenideDriver().navigate().refresh();
// Wait for the page to load and create screenshot with changed User-Agent
E(byCssSelector("[action=\"/search\"]")).waitFor(10).untilIsVisible()
.saveScreenshot("custom_user_agent.png");
// Set User-Agent to empty string value
setUserAgent("");
// Refresh the page
getSelenideDriver().navigate().refresh();
// Wait for the page to load and create screenshot with empty User-Agent
E(byCssSelector("[action=\"/search\"]")).waitFor(10).untilIsVisible()
.saveScreenshot("empty_user_agent.png");
// Reset User-Agent to original value
setUserAgent(null);
// Refresh the page
getSelenideDriver().navigate().refresh();
// Wait for the page to load and create screenshot with reset User-Agent
E(byCssSelector("[action=\"/search\"]")).waitFor(10).untilIsVisible()
.saveScreenshot("reset_user_agent.png");
}
User-Agent will revert to original value in browser built-in pages and WebRTC dump.