Home > front end >  Not being able to interact with Selenium in the Select class
Not being able to interact with Selenium in the Select class

Time:12-08

I am writing as I support with screenshots but it does not recognize xpath.

[1] (https://i.stack.imgur.com/b1L2G.png)

[2] (https://i.stack.imgur.com/2ypQV.png)

[error] (https://i.stack.imgur.com/DmgNa.png)

I want to run the "Select" method from the xpath I'm looking for and access the desired "value" value and interact.

       WebElement elem = driver.findElement(By.xpath("//select[@id='appointments_consulate_appointment_facility_id']"));

    Select sel = new Select(elem);
    sel.selectByValue("125");

Full code:

    public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new EdgeDriver();

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

    driver.get("https://ais.usvisa-info.com/tr-tr/niv/schedule/44581745/appointment");
    driver.
            findElement(By.xpath("/html/body/div[7]/div[3]/div/button"))
            .click();
    driver.findElement(By.xpath("//*[@id=\"user_email\"]"))
            .sendKeys("blablabla");
    driver.findElement(By.xpath("//*[@id=\"user_password\"]"))
            .sendKeys("blablabla") ;
    driver.findElement(By.xpath("//*[@id=\"sign_in_form\"]/div[3]/label/div"))
            .click();
    driver.findElement(By.xpath("//*[@id=\"sign_in_form\"]/p[1]/input"))
            .click();
    
    WebElement elem = driver.findElement(By.xpath("//select[@id='appointments_consulate_appointment_facility_id']"));

    Select sel = new Select(elem);
    sel.selectByValue("125");

CodePudding user response:

What if you try?:

driver.findElement(By.xpath("//*[@id=\"sign_in_form\"]/p[1]/input"))
        .click();

Thread.sleep(5000);
driver.findElement(By.xpath("//select[@id='appointments_consulate_appointment_facility_id']")).selectByValue("125");

You will need to import package:

package com.journaldev.threads;

I'm thinking maybe the element is not present when you try to interact with it

  • Related