selenium-webdriverselenium-chromedriverselenium-grid

Website is detecting Selenium bot, is there any other website that can be tested for the sake of a Selenium tutorial


I am testing the Lufthansa website with a Selenium webdriver test. The FROM field is already input with the string "Casablanca", so I click on it and I clear it. But the problem is that when I click on it again for a second time to write in an input, it is again automatically filled in with the input value "Casablanca". The problem is that this website is detecting the bot(your selenium script). And hence it is blocking any performed actions. If you want to check that, manually refresh the page. You will see Access Denied error. –How can I fix this problem? Is there any other website that I could test and that would not detect the Selenium bot? I just want to create a tutorial so the website is not really important. enter image description here

package Test;
// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
public class AirLineTest {
  private WebDriver driver;
  private Map<String, Object> vars;
  JavascriptExecutor js;
  @Before
  public void setUp() {
    driver = new ChromeDriver();
    js = (JavascriptExecutor) driver;
    vars = new HashMap<String, Object>();
  }
  @After
  public void tearDown() {
    driver.quit();
  }
  @Test
  public void test() {
   
    driver.get("https://www.lufthansa.com/ma/en/homepage");
    driver.manage().window().setSize(new Dimension(1552, 840));
    driver.findElement(By.xpath("//*[@id=\"cm-acceptAll\"]")).click(); 
    
    driver.findElement(By.xpath("//input[@placeholder='From']")).click();
    driver.findElement(By.xpath("//input[@placeholder='From']")).clear();
    driver.findElement(By.xpath("//input[@placeholder='From']")).click();
    driver.findElement(By.xpath("//input[@placeholder='From']")).sendKeys("Rabat"); 
   
    driver.findElement(By.xpath("//input[@placeholder='To']")).click();
    driver.findElement(By.xpath("//input[@placeholder='To']")).clear();
    driver.findElement(By.xpath("//input[@placeholder='To']")).sendKeys("New York"); 
    driver.close(); 
  }
}

Solution

  • It's quite surprising that selenium is detected because usually when you set up the driver and profile, it looks exactly like someone is operating the browser.

    To set up the profile, you can follow this answer: How to use Chrome Profile in Selenium Webdriver Python 3

    For the test websites, I'd say most of the websites don't have the detections. To avoid any trouble, I suggest you visit some legacy websites that are not popular today but still accessible.