Unable to select the item from the webdriver selenium drop-down menu

advertisements

I am trying to select a item from dropdown since in html tag is not used as Select for dropdown, then I used to select dropdown item through Action.

My question is this standard way to code to select dropdown item in this situation or should should i need to change my code.

    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.support.ui.Select;

    public class test
    {
    static WebDriver driver;
    public static void main(String[] args)
    {
        System.setProperty("webdriver.chrome.driver", "D:\\rakesh\\software\\selenium browser\\New folder\\chromedriver.exe");
        driver=new ChromeDriver();
        driver.get("https://app.crossover.com/x/marketplace/available-jobs");
        driver.manage().window().maximize();
        driver.findElement(By.cssSelector(".btn.btn-default.form-control.ui-select-toggle")).click();

        WebElement dropdonw_ele = driver.findElement(By.xpath("/html/body/div[2]/div[3]/div/div/div/div[2]/form/div/div[2]/job-label-select/div/ul/li/div[5]/span/div/span"));
        Actions act = new Actions(driver);
        act.build();
        act.moveToElement(dropdonw_ele).click();
        act.perform();
    }
}


Try this way.
Note: Use Relative xpath, not absolute xpath.

driver.get("https://app.crossover.com/x/marketplace/available-jobs");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.findElement(By.xpath("//span[@class='ui-select-match-text pull-left']/span")).click();            //click on All job categories first
Thread.sleep(3500);
driver.findElement(By.xpath("//div[@class='ng-scope']/span[contains(text(), 'C++')]")).click();     //By using xpath method click on C++ from the dropdown selection.
Thread.sleep(3500);