我的任务是取消选中复选框,然后再次选中 复选框。
这是网站(在代码中提及了要遍历的所有 Selenium 脚本)。
作为初学者,我正在研究 Selenium Web驱动程序,那么我在运行Selenium测试脚本时被卡在一个地方,我想取消选中底部的复选框,其中同意有关Naukri.com使用的条款和条件
我已经查看了默认的Mailer&Communications设置。
我们将不胜感激。
错误堆栈跟踪为:
Exception in thread "main" org.openqa.selenium.WebDriverException:
Element is not clickable at the point. Other element would receive the
click: <label for="term" class="customChkBoxLbl chkboxLbl"></label>
到目前为止我尝试过的代码:
WebDriver driver13=new FirefoxDriver();
driver13.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
driver13.get("https://www.naukri.com/");
driver13.manage().window().maximize();
driver13.findElement(By.xpath("//*[@id=\"p0widget\"]/div[1]/div[1]/div[1]/input[1]")).click();
driver13.findElement(By.xpath("//button[@value='exp']")).click();
我也尝试了这个,但是得到了如下异常:
尽管我编写了正确的XPath,但以下代码仍无法正常工作:
Actions a = new Actions(driver13);
a.moveToElement(driver13.findElement(By.xpath("//input[@name='term']"))).click().build().perform();
答案 0 :(得分:0)
点击“我是专业人士”后,您可以使用以下代码:
wait = new WebDriverWait(driver,20);
driver.manage().window().maximize();
driver.get("https://my.naukri.com/account/createaccount");
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@name='userType' and contains(text(),'Professional')]"))).click();
WebElement checkBox = driver.findElement(By.id("term"));
System.out.println(checkBox.isSelected()); // this should print True (Because it is checked)
JavascriptExecutor executor = (JavascriptExecutor)driver;
Thread.sleep(2000); // for visualization purpose , you can remove it after the execution
executor.executeScript("arguments[0].click();", checkBox); // Click it and Uncheck it.
System.out.println(checkBox.isSelected()); // this should print False (Because it is unchecked now)
Thread.sleep(2000); //for visualization purpose , you can remove it after the execution
executor.executeScript("arguments[0].click();", checkBox); //check it again
System.out.println(checkBox.isSelected()); // this should print True (Because it is checked)