0

My target application use <script type="text/javascript">debugger;</script> So my page is blocked by break point.

How disable debugger on chrome webdriver in Java?

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import com.github.noraui.utils.Utilities.OperatingSystem;
import com.github.noraui.utils.Utilities.SystemArchitecture;

public class Bot {

    public static void main(String[] args) {
        final OperatingSystem currentOperatingSystem = OperatingSystem.getCurrentOperatingSystem();
        String pathWebdriver = String.format("src/test/resources/drivers/%s/googlechrome/%s/chromedriver%s", currentOperatingSystem.getOperatingSystemDir(),
                SystemArchitecture.getCurrentSystemArchitecture().getSystemArchitectureName(), currentOperatingSystem.getSuffixBinary());
        System.setProperty("webdriver.chrome.driver", pathWebdriver);

        ChromeOptions options = new ChromeOptions();
        WebDriver driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://rd.huangpuqu.sh.cn/website/html/shprd/shprd_tpxw/List/list_0.htm");

    }

}

I think, add javascipt code (revert of debugger;) by this:

((JavascriptExecutor) driver).executeScript("...");

EDIT WITH HEADLESS MODE + SCREENSHOT:

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import com.github.noraui.utils.Utilities.OperatingSystem;
import com.github.noraui.utils.Utilities.SystemArchitecture;

public class Bot {

    public static void main(String[] args) throws IOException {
        final OperatingSystem currentOperatingSystem = OperatingSystem.getCurrentOperatingSystem();
        String pathWebdriver = String.format("src/test/resources/drivers/%s/googlechrome/%s/chromedriver%s", currentOperatingSystem.getOperatingSystemDir(),
                SystemArchitecture.getCurrentSystemArchitecture().getSystemArchitectureName(), currentOperatingSystem.getSuffixBinary());
        System.setProperty("webdriver.chrome.driver", pathWebdriver);

        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless");
        WebDriver driver = new ChromeDriver(options);
        driver.get("http://rd.huangpuqu.sh.cn/website/html/shprd/shprd_tpxw/List/list_0.htm");

        final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
        FileUtils.forceMkdir(new File(System.getProperty("user.dir") + File.separator + "downloadFiles"));
        FileUtils.writeByteArrayToFile(new File(System.getProperty("user.dir") + File.separator + "downloadFiles" + File.separator + "bot.jpg"), screenshot);
    }

}

The result is same, my sceenshot is white.

Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
  • Is your chrome running in `headless` mode? You can try `Robot` class key press events. like `(Ctrl + F8)` key used to `disable` breakpoints in inspect window. – hrdkisback Jun 20 '19 at 10:13
  • @hrdkisback, I add `headless` mode but how to add `Ctrl + F8`? – Stéphane GRILLON Jun 20 '19 at 11:09
  • Please refer this link https://stackoverflow.com/questions/49459040/why-do-we-need-robot-class-when-we-have-actions-class-in-selenium – hrdkisback Jun 20 '19 at 11:18
  • @hrdkisback, I add this but do not work again: `Robot r = new Robot(); r.keyPress(KeyEvent.VK_CONTROL); r.keyPress(KeyEvent.VK_F8);` – Stéphane GRILLON Jun 20 '19 at 11:43
  • Try `Thread.sleep(500);` between both key press events. – hrdkisback Jun 20 '19 at 12:06
  • Also one thing that `Robot` class does not support in headless mode, So if your are trying above solution with `headless` mode, it'll not work. – hrdkisback Jun 20 '19 at 13:26
  • @hrdkisback, not work with add sleep (headless or not) – Stéphane GRILLON Jun 20 '19 at 14:59
  • Check my answer with workaround [here](https://stackoverflow.com/questions/56537191/how-to-deal-with-the-overlay-paused-in-debugger-while-automated-test-execution-u) – supputuri Jun 20 '19 at 15:51
  • I know [disabling the javascript](https://stackoverflow.com/questions/56537191/how-to-deal-with-the-overlay-paused-in-debugger-while-automated-test-execution-u) is not a correct way, but in the given scenario that's the only option I can think of to handle the `unnecessary debugger` in the html which is causing the issue. – supputuri Jun 20 '19 at 15:53
  • @supputuri, you answer do not work, you can try run java code present in description. – Stéphane GRILLON Jun 21 '19 at 06:16

0 Answers0