H Athukorala
H Athukorala

Reputation: 853

Getting NoSuchElementException: no such element: Unable to locate element

I am trying to automate this from. But when I try to send a text to a text fields it is getting NoSuchElementException. I have tried webdriverwait also. But no luck. There is a popup on top of the window. I closed it and also I tried adding --disable-popup-blocking argument. But still it is not working. So anybody can tell me what I am doing wrong here? I highly appreciate that. Thank you.

    System.setProperty("webdriver.chrome.driver", "chromedriver/chromedriver.exe");

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-popup-blocking");
    options.addArguments("chrome.switches", "--disable-extensions");

    WebDriver driver = new ChromeDriver(options);
    driver.manage().window().maximize();
    driver.get(URL);

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    JavascriptExecutor jse = (JavascriptExecutor) driver;
    jse.executeScript("window.scrollBy(0,250)");

    driver.findElement(By.cssSelector("#txt_insert2055107")).click();
    driver.findElement(By.cssSelector("#txt_insert2055107")).sendKeys("Test");
    driver.findElement(By.id("txt_insert2055108")).click();
    driver.findElement(By.id("txt_insert2055108")).sendKeys("Test");
    driver.findElement(By.id("btnsubmit")).click();

    driver.close();

Upvotes: 0

Views: 380

Answers (1)

SeleniumUser
SeleniumUser

Reputation: 4177

You cant send text on your input because you need to switch to iframe firts. Please find below working code:

https://www.frontrush.com/FR_Web_App/Player/PlayerSubmit.aspx?sid=MTA1NTc=-9M6ha/5BuDo=&ptype=recruit

code:

        driver.get("https://columbiacougars.com/sb_output.aspx?frform=8&path=mbball");
        driver.switchTo().frame(0);

        driver.manage().window().maximize();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        WebDriverWait wait = new WebDriverWait(driver, 10);

        Actions action = new Actions(driver);
        WebElement firstName=wait.until(ExpectedConditions.elementToBeClickable(By.id("txt_insert2055107")));
        ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", firstName);
        action.moveToElement(firstName).sendKeys("Test").perform();
        WebElement lastName=wait.until(ExpectedConditions.elementToBeClickable(By.id("txt_insert2055108")));
        ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", lastName);
        lastName.sendKeys("Test");
        action.moveToElement(lastName).sendKeys("Test").perform();
        WebElement clickElement=wait.until(ExpectedConditions.elementToBeClickable(By.name("btnsubmit")));
        ((JavascriptExecutor)driver).executeScript("arguments[0].click();", clickElement);
        driver.close();

enter image description here

Upvotes: 1

Related Questions