我正在尝试自动化Naukari.com CREATE JOB ALERT页面,因为我们有INDUSTRY字段和JOB ROLE字段。两者都是带复选框的组合框。对于INDUSTRY字段,我使用下面的脚本。
//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();
但是对于JOB ROLE字段,我再次面临这个问题,因为div类是相同的。我也尝试过使用//input[contains(@id,'given_id')]")).click();
但它不起作用。请帮忙!!
答案 0 :(得分:0)
尝试以下代码(适用于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();