点击复选框,使用Selenium Java自动化。

huangapple go评论69阅读模式
英文:

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(&quot;https://www.sugarcrm.com/request-demo/&quot;);
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(30));
		
// Accept cookies
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(&quot;//button[text()=&#39;Accept All Cookies&#39;]&quot;))).click();
		
// Click checkbox
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(&quot;//*[@id=&#39;doi0&#39;]&quot;))).click();

huangapple
  • 本文由 发表于 2023年7月17日 18:32:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703601.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定