英文:
Clicking on checkbox with Selenium java automation
问题
我想点击注册表格下方的复选框,基于提供的代码,但似乎不起作用。
//System.setProperty("webdriver.chrome.driver","C:\\browserdrivers\\chromedriver.exe");
ChromeDriverManager.getInstance().setup();
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.sugarcrm.com/request-demo/");
driver.manage().window().maximize();
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll\"]"))).click();
driver.findElement(By.xpath("//*[@id=\"doi0\"]")).click();
我还尝试了 findElement(By.name ("doi")
,这似乎也不起作用。
英文:
I want to click on the checkbox below this registration form based on the given code by it doesn't seem to be working.
//System.setProperty("webdriver.chrome.driver","C:\\browserdrivers\\chromedriver.exe");
ChromeDriverManager.getInstance().setup();
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.sugarcrm.com/request-demo/");
driver.manage().window().maximize();
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll\"]"))).click();
driver.findElement(By.xpath("//*[@id=\"doi0\"]")).click();
I had also tried findElement(By.name ("doi")
, this doesn't seem to work either.
答案1
得分: 1
driver.get("https://www.sugarcrm.com/request-demo/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(TimeOut.Seconds(20));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
// 接受 Cookie
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Accept All Cookies']"))).click();
Thread.sleep(5000);
// 点击复选框
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='doi']"))).click();
英文:
driver.get("https://www.sugarcrm.com/request-demo/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(TimeOut.Seconds(20));
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(30));
// Accept cookies
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Accept All Cookies']"))).click();
Thread.sleep(5000);
// Click checkbox
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='doi']"))).click();
答案2
得分: 0
只需首先单击Accept Cookie按钮。然后尝试定位并单击复选框。
请参考下面的代码:
driver.get("https://www.sugarcrm.com/request-demo/");
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
// 接受Cookie
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Accept All Cookies']"))).click();
// 单击复选框
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='doi0']"))).click();
英文:
You just have to click on <kbd>Accept Cookie</kbd> button first. And then try to locate and click checkbox.
Refer the code below:
driver.get("https://www.sugarcrm.com/request-demo/");
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(30));
// Accept cookies
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Accept All Cookies']"))).click();
// Click checkbox
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='doi0']"))).click();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论