0

While practicing Selenium, I tried to automate the British Airways site, where auto-suggestion dropdowns are used. When manually entering a few letters, the dropdowns display suggestions; when automating it, they don't, even if I use the wait method. I was told sites like this prevent automation as security measure, but is it so, please?

Here's my code:

driver.get("https://www.britishairways.com/");
driver.manage().window().maximize();

driver.findElement(By.id("from")).click();
driver.findElement(By.id("from")).sendKeys("tor");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
dmeps
  • 1
  • 2
  • You can launch the Selenium-controlled and Chrome side-by-side and check the console for activity. It's possible that when you manually click and type in the box, it's selecting different control due to a script. – Martheen Jun 09 '20 at 02:15
  • @Martheen, the control is the same. What's Selenium-controlled, though? – dmeps Jun 10 '20 at 02:01
  • Unless you use headless option, there should be chrome window that's controlled by selenium, right? – Martheen Jun 10 '20 at 05:13
  • Ah, I see what you meant. But as I mentioned, it's all the same. – dmeps Jun 11 '20 at 02:13

2 Answers2

0

I didn't find any bot detection mechanism with in the British Airways website https://www.britishairways.com/.

To send a character sequence to the From field within the website, as the element is an Angular element you need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    driver.get("https://www.britishairways.com/travel/home/public/en_in/");
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#from[name=\"searchEntry\"]"))).sendKeys("tor");
    
  • xpath:

    driver.get("https://www.britishairways.com/travel/home/public/en_in/");
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='from' and @name=\"searchEntry\"]"))).sendKeys("tor");
    

Browser Snapshot:

britishairways

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for showing me the method I'm not familiar with, but - as your screenshot demonstrates - it doesn't work either. – dmeps Jun 10 '20 at 02:19
0

I would definitely use xpath or css selectors iso "id" when working on sites like that. Ids are usually less trusted attributes.