Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between automating using http requests vs selenium webdriver?

I am a bot developer in selenium webdriver Java and I'm using a browser HtmlunitDriver headless but it's complicated when I have to deal with javascript, so, which is better when I have to automate page? Sending HTTP get and post requests or continue using webdriver?

I'm confused because, for example, how can I click a button and wait for a page to load (example: when I open a page like Ad.fly) and I have to wait 5 seconds until the button is ready sending http request, this is what I am confused by, thanks a lot for your answers!!

like image 273
Leo Galindo Avatar asked Feb 17 '26 15:02

Leo Galindo


1 Answers

Use HTTP requests if you just want to make calls (i.e. to REST services). Use selenium (or other web automation tools) if you need to simulate browser behaviour (i.e. run javascript in the page). HTTP is generally preferable if you have the option - services are more stable than page structure (particularly if there's a published interface) and are more oftened designed to be machine-readable. Web pages are designed for humans using web browsers, so they can change frequently, and adds a lot of overhead which doesn't make sense in a machine interface.

So, I'd suggest - look through the sequence of user actions you're trying to automate. If you can express those as a simple sequence of HTTP requests, I'd do it that way. If you need to run client-side javascript, or use other browser functionality, use selenium.

like image 79
hugh Avatar answered Feb 20 '26 04:02

hugh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!