zerocool
zerocool

Reputation: 833

faking hostname in selenium

I'm trying to test response time of webpages hosted on many backends. These hosts are behind load balancer and above that I have my domain.com.

I want to use python+selenium on these backends but with spoofed hostname, without messing with /etc/hosts or running fake DNS servers. Is that possible with pure selenium drivers?

To illustrate problem better, here is what's possible in curl and I'd like to do the same with python+selenium:

Upvotes: 0

Views: 2319

Answers (2)

Ian Lesperance
Ian Lesperance

Reputation: 5139

In short, no.

Selenium drives browsers using the WebDriver standard, which is by definition limited to interactions with page content. Even though you can provide Selenium with configuration options for the browser, no browser provides control over Host headers or DNS resolution outside of a proxy.

But even if you could initiate a request for a particular IP address with a custom Host header, subsequent requests triggered by the content (redirection; downloading of page assets; AJAX calls; etc) would still be outside of your control and are prohibited from customizing the Host header, leading the browser to fall back to standard DNS resolution.

Your only options are modifying the local DNS resolution (via /etc/hosts) or providing an alternative (via a proxy).

Upvotes: 0

ChatterOne
ChatterOne

Reputation: 3541

If you're on a UNIX system, you can try something as explained here:

https://unix.stackexchange.com/questions/10438/can-i-create-a-user-specific-hosts-file-to-complement-etc-hosts

Basically you still use a hosts file, but it's only for you, located in ~/.hosts, setting the HOSTALIASESenvironment variable.

Upvotes: 1

Related Questions