有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

具有相同DIV类的java自动组合框

我正在尝试自动化Naukari。com创建工作提醒页面,我们有行业字段和工作角色字段。两者都是带有复选框的组合框。对于工业领域,我使用了下面的脚本

 //Clicking on the industry dropdown
 //driver.findElement(By.xpath("//input[contains(@placeholder,'Type or   Select')]")).click();

 //Selecting the checkbox containing text as "Accounting"
 //driver.findElement(By.xpath("//ul[@class='ChkboxEnb']//a[contains(text(),'Accounting')]")).click();

 //Selecting the checkbox containing text as 'Government' 
 //driver.findElement(By.xpath("//ul[@class='ChkboxEnb']//a[contains(text(),'Government')]")).click();

但对于工作角色领域,我再次面临这个问题,因为div的课程是一样的。我还试着使用//input[contains(@id,'given_id')]")).click();

但它不起作用。请帮忙


共 (1) 个答案

  1. # 1 楼答案

    请尝试以下代码(适用于FF和Chrome):

        //Sending blank to the industry dropdown so the list is visible
        driver.findElement(By.xpath("//input[@id='cjaInd']")).sendKeys("");
    
        Actions act = new Actions(driver);
    
        //Selecting the checkbox containing text exactly as "Accounting , Finance"
        act.moveToElement(driver.findElement(By.xpath("//div[@id='indCja']//ul[@class='ChkboxEnb']//a[.='Accounting , Finance']"))).click().perform();
    
        //Selecting the checkbox containing text exactly as 'Strategy , Management Consulting Firms' 
        act.moveToElement(driver.findElement(By.xpath("//div[@id='indCja']//ul[@class='ChkboxEnb']//a[.='Strategy , Management Consulting Firms']"))).click().perform();
    
        //For clicking outside so as the dropdown closes and we can proceed with other action(s)
        act.moveToElement(driver.findElement(By.xpath("//label[.='Industry']"))).click().perform();
    
        //Sending blank to the Job Category dropdown so the list is visible
        driver.findElement(By.xpath("//input[@id='cjaJob']")).sendKeys("");
    
        //Selecting the checkbox containing text exactly as Application Programming, Maintenance
        act.moveToElement(driver.findElement(By.xpath("//div[@id='jcCja']//ul[@class='ChkboxEnb']//a[.='Application Programming, Maintenance']"))).click().perform();
    
        //Selecting the checkbox containing text exactly as "Site Engineering, Project Management"
        act.moveToElement(driver.findElement(By.xpath("//div[@id='jcCja']//ul[@class='ChkboxEnb']//a[.='Site Engineering, Project Management']"))).click().perform();
    
        //For clicking outside so as the dropdown closes and we can proceed with other action(s)
        act.moveToElement(driver.findElement(By.xpath("//label[.='Industry']"))).click().perform();