0

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". How can I fix this problem? 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(); 
  }
}
  • 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. – Shawn Jun 19 '23 at 10:23
  • Is there any way to stop the website from blocking my performed actions? – Mouna Camelia Hammoudi Jun 20 '23 at 07:28
  • If you use Python-selenium, there is a library which you can use for this purpose, it's called `undetected-chromedriver`. Since you are on Java, suggest referring these links if it helps - https://stackoverflow.com/a/51236874/7598774 https://stackoverflow.com/questions/56528631/is-there-a-version-of-selenium-webdriver-that-is-not-detectable – Shawn Jun 20 '23 at 08:37
  • For Java clients the faker module still works. – undetected Selenium Jun 21 '23 at 00:09
  • what would need to be changed from a code perspective? Could you help me rewrite the code? – Mouna Camelia Hammoudi Jun 21 '23 at 09:12

0 Answers0