Ramco Ramco

Ramco Ramco

  • 429
  • 3.5k
  • 563.9k

javascript error: {"status":60,"value":"[object HTMLDivElement]

Apr 7 2024 3:32 PM

Hi

 I am getting error - javascript error: {"status":60,"value":"[object HTMLDivElement] has no size and location"}
  (Session info: chrome=123.0.6312.106) on below line

private async void btnRun_Click(object sender, EventArgs e) => await Start();

async Task Start()
        {
            _isRunning = true;
            btnStop.Enabled = _isRunning;
            btnRun.Enabled = !_isRunning;

            var options = new ChromeOptions();

            if (chkHeadless.Checked)
                options.AddArgument("--headless=new");

            if (chkMuteAudio.Checked)
                options.AddArgument("--mute-audio");

            if (chkPreventDetection.Checked)
            {
                options.AddArgument("--incognito");
                options.AddArgument("disable-infobars");
                options.AddExcludedArgument("enable-automation");
                options.AddAdditionalChromeOption("useAutomationExtension", false);
            }

            var service = ChromeDriverService.CreateDefaultService();
            service.HideCommandPromptWindow = true;

            _driver = new ChromeDriver(service, options);
            _driver
                .Manage()
                .Window
                .Size = new Size(1024, 768);

            var isMuted = chkMuteAudio.Checked;
            var randomDelay = chkDelay.Checked;
            var videoKey = txtVideoKey.Text;
            var instances = updnInstances.Value;
            for (var count = 1; count <= instances; count++)
            {
                if (!_isRunning)
                    return;

                await Task.Run(async () =>
                {
                    if (!_isRunning)
                        return;

                    OpenVideo(videoKey, isMuted);

                    if (randomDelay)
                        await Task.Delay(_random.Next(5, 10) * 1000);
                });
            }

            var replayCheckInSeconds = (int)updnReplay.Value * 1000 * 60;
            if (replayCheckInSeconds == 0)
                return;

                        await Task.Run(() =>
            {
                if (!_isRunning)
                    return;

                dgvWindows.BeginInvoke(() =>
                {
                    foreach (DataGridViewRow row in dgvWindows.Rows)
                    {
                        var handle = row.Cells[0].Value.ToString();

                        _driver
                            .SwitchTo()
                            .Window(handle);

                        var btnPlay = GetElement(XPATH_PLAY);
                        btnPlay?.Click();

                        row.Cells[2].Value = "Playing";
                    }
                });

                Task.Delay(replayCheckInSeconds);
            });
        }

Thanks


Answers (1)