M
M
Maxim K2020-07-13 16:06:30
C++ / C#
Maxim K, 2020-07-13 16:06:30

How to assign a value to a TextBox in cefsharp?

Hello. I'm trying to execute scripts and take the value in the text field

private void button1_Click(object sender, EventArgs e)
        {
          textBox1.Text =  chromeBrowser.ExecuteScriptAsync("document.querySelector('#content > div > div:nth-child(1) > div > div > div:nth-child(2) > div > div.box-gray.aligncenter').outerText;");
        }


I get the error:
Severity Code Description Project File Line Suppression State
Error CS0029 Cannot implicitly convert type 'void' to 'string' CefSharp H:\C# projects\CefSharp\CefSharp\Form1.cs 84 Active

Tried to convert - didn't work, what am I doing wrong ??

this doesn't work either:
string textData = "document.querySelector('#content > div > div:nth-child(1) > div > div > div:nth-child(2) > div > div.box-gray.aligncenter').outerText;";
            textBox1.Text = chromeBrowser.ExecuteScriptAsync(textData);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BasiC2k, 2020-07-13
@BasiC2k

Try using XPath https://metanit.com/sharp/tutorial/16.4.php
to extract the node and its value.
This method is convenient in that you can check the paths to the node - through the debug console of the browser.
C js I would contact last.

M
Maxim K, 2020-07-13
@mkvmaks

That doesn't work either :(

string script = string.Format("document.querySelector('#content > div > div:nth-child(1) > div > div > div:nth-child(2) > div > div.box-gray.aligncenter').outerText;");
            chromeBrowser.EvaluateScriptAsync(script).ContinueWith(x =>
            {
                var response = x.Result;

                if (response.Success && response.Result != null)
                {
                    var startDate = response.Result;
                    textBox1.Text = Convert.ToString(startDate);
                }
            });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question