Hack Forums
[.NET] vb.net cef browser click on button with no id help me pls - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] vb.net cef browser click on button with no id help me pls (/showthread.php?tid=6106624)



vb.net cef browser click on button with no id help me pls - triplextreme - Sep 1, 2020

Hi every one i try to click on this button "<button type="submit" class="button" name="login" value="Log in">Log in</button>" bu what so ever i couldn't find a solution i tried with this code

  Dim jsScript2 As String = <js><![CDATA[
        document.all("login").click();
                    ]]></js>.Value
            bs.ExecuteScriptAsync(jsScript2)
this is just working with id buttons is not work on this many thanks in advance


RE: vb.net cef browser click on button with no id help me pls - TTGXINSTINCT - Sep 3, 2020

I think we need a little bit more information to help you, from what I can see, you want to click a button that then clicks the browsers loaded page that has a login button on it?

To do so you can get each element that has button and then click the one that has the value "Log in"

Check out this link to get an idea on how to get that to  work: https://stackoverflow.com/questions/11101060/programatically-clicking-an-html-button-by-vb-net


RE: vb.net cef browser click on button with no id help me pls - o3xa - Sep 7, 2020

Looks like your using the CefSharp .net browser github.com[slash]cefsharp[slash]CefSharp so you just need to inject the correct javascript to select/click the button


RE: vb.net cef browser click on button with no id help me pls - triplextreme - Sep 7, 2020

thanks for every one to reply to me but my problem is i want to make a click on the button what it not have a id on the id buttons works fine with a code above but others are not and i looking for a solution for that if is possible thank you in advance


RE: vb.net cef browser click on button with no id help me pls - o3xa - Sep 7, 2020

So you could use something like the following:


Code
// get all the elements with the class 'button'
var btns = document.querySelectorAll(".button");

// loop through all the elements found
for (var i = 0; i < btns.length; i++) {
    // click all of the buttons
    eventFire(btns[i], 'click');

    // console log test
    console.log('btn: ', btns[i]);
}

// simulate a click
function eventFire(el, etype){
  if (el.fireEvent) {
    el.fireEvent('on' + etype);
  } else {
    var evObj = document.createEvent('Events');
    evObj.initEvent(etype, true, false);
    el.dispatchEvent(evObj);
  }
}

If there are multiple elements with the class name 'button' and you'd only want to click that specific element (button), you can do a few extra checks in the loop to narrow it down base on the info that the button has got.

e.g.
Code
// loop through all the elements found
for (var i = 0; i < btns.length; i++) {

    // check the name and value attributes
    // Then only click the button if the name = login and value = Log in )
    if( btns[i].getAttribute('name') == 'login' && btns[i].getAttribute('value') == 'Log in'){
        // click all of the buttons
       eventFire(btns[i], 'click');
    }
   

    // console log test
    console.log('btn: ', btns[i]);
}



RE: vb.net cef browser click on button with no id help me pls - triplextreme - Sep 15, 2020

thanks for the answer but i looking for a solution in vb.net but the above code not working with my code so i just suggest it is a different code


RE: vb.net cef browser click on button with no id help me pls - SaketSaket - Sep 15, 2020

(Sep 15, 2020 07:41 AM)triplextreme Wrote:  thanks for the answer but i looking for a solution in vb.net but the above code not working with my code so i just suggest it is a different code

the code provided above is in c#... just convert it to vb.net using following online converter & use it...

https://converter.telerik.com/


RE: vb.net cef browser click on button with no id help me pls - Dredd - Sep 15, 2020

(Sep 15, 2020 07:41 AM)triplextreme Wrote:  thanks for the answer but i looking for a solution in vb.net but the above code not working with my code so i just suggest it is a different code

Code
// loop through all the elements found
for i as integer = 0 to btns.length

    // check the name and value attributes
    // Then only click the button if the name = login and value = Log in )
    if btns(i).getAttribute("name") = "login" and btns(i).getAttribute("value") = "Log in" then
        // click all of the buttons
       eventFire(btns(i), "click")
    End If
  

    // console log test
    console.log("Button - " + btns(i).tostring())
next

Roughly converted it to VB of the top of my head try that.