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.
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();
}
}