0

I am learning Selenium and using jetblue.com for test. When I click on "FIND IT" button in homepage by providing all the required values, the page simply refreshes instead of going to the next screen. Can anyone advise where I am going wrong?

I tried using .click() and submit(). but not the control does not go the next page

package testCases;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

public class Calendar {

@Test
public void calControl() throws InterruptedException
{
    System.setProperty("webdriver.chrome.driver","C:\\chromedriver_win32\\chromedriver.exe");   

    ChromeOptions options = new ChromeOptions();
    options.addArguments("disable-infobars");
    options.addArguments("--start-maximized");

    WebDriver driver= new ChromeDriver(options);
    driver.get("https://www.jetblue.com");
//  driver.findElement(By.className("input-group-btn")).click();
    Thread.sleep(3000);
//  driver.findElement(By.cssSelector("button[class='btn pull-right']")).click();

    List<WebElement> count = driver.findElements(By.className("input-group-btn"));
    int count1 = driver.findElements(By.className("input-group-btn")).size();
    count.get(0).click();
    Thread.sleep(3000);
    driver.findElement(By.xpath("//table[@class='calendar']//td//span[.=27]")).click();

    System.out.println(count1);
    for (int i = 0;i<count1;i++)
    {
        System.out.println(count.get(i).toString());
    }
    Thread.sleep(3000);
    count.get(1).click();
    Thread.sleep(3000);
    //driver.findElement(By.xpath("//button/span[@class='foreground-sprite-calendarforward']")).click();
    List<WebElement> pullRight = driver.findElements(By.cssSelector("button[class='btn pull-right']"));
    int count2 = driver.findElements(By.cssSelector("button[class='btn pull-right']")).size();


    do
    {
    pullRight.get(1).click();
    } while (driver.findElement(By.xpath("//div/strong[.='March 2018']")).isDisplayed()==false);

    List<WebElement> returnDate = driver.findElements(By.xpath("//table[@class='calendar']//td//span[.=8]"));
    int returnCount = driver.findElements(By.xpath("//table[@class='calendar']//td//span[.=3]")).size();

    returnDate.get(1).click();
    //driver.findElement(By.xpath("//input[@class='piejs']")).click(); Find Button

    WebElement from = driver.findElement(By.id("jbBookerDepart"));
    from.click();
    Thread.sleep(2000);
    from.sendKeys("DXB");
    from.sendKeys(Keys.TAB);

    Thread.sleep(2000);
    WebElement to = driver.findElement(By.id("jbBookerArrive"));
    to.click();
    Thread.sleep(2000);
    to.sendKeys("SFO");
    to.sendKeys(Keys.TAB);
    Thread.sleep(2000);

    WebElement findButton = driver.findElement(By.xpath("//*[@id='login-search-wrap']/div[3]/div/div[3]/form/input[5]"));

    //System.out.println("Value of button:" +driver.findElement(By.xpath("//*[@id='login-search-wrap']/div[3]/div/div[3]/form/input[5]")).toString());

    /*Actions a = new Actions(driver);
    //a.click(findButton).build().perform();
    a.clickAndHold(findButton).doubleClick().build().perform();*/

    /*driver.findElement(By.cssSelector("input[value='Find it']")).submit();
    driver.findElement(By.xpath("input[value='Find it']")).submit();*/
    System.out.println(findButton.isEnabled());
    findButton.click();

    Thread.sleep(5000);
}
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Nel
  • 1
  • 4
  • Which line? Do you see any error? What should be the expected behavior? – undetected Selenium Feb 10 '18 at 08:49
  • I am not getting error, but in this line findButton.click(); The form should submit data upon clicking Find It button and proceed to next page. Instead currently the page is refreshing on clicking Find It button and stays on the current page – Nel Feb 10 '18 at 09:08

1 Answers1

0

That page is probably using anti-selenium software. I debugged your code several times, and here are my observations - I tried do perform some operations by hand, and some by WebDriver, and the result is: If ANY operation is performed by WebDriver, the form will not submit. That even includes opening of the page. They probably set some flag whenever an automated software is performing any action on their page.

Have a look at this answer. I don't know what anti-bot method they may be using, but this could be the first step.

xinaiz
  • 7,744
  • 6
  • 34
  • 78