locked
on the website there is same id RRS feed

  • Question

  • on the website there is same id textbox but when i am writing 
            WebBrowser1.Document.All("username").SetAttribute("value", username)
    its writen different textbox with same id "username"

    <input name="username" id="username" type="text" class="user" autocomplete="off"
    placeholder="Kullanici Adi">

    i need to reach second field but i couldnt reach 
    <input type="text" id="username" class="input4"
     autocomplete="off" name="username" value="" required="" 
    data-required="" data-pattern="^[a-zA-Z][a-zA-Z0-9]+$" 
    data-minlenght="6" data-maxlenght="12"
     onkeyup="clearNonAlphaNum(this)">

    please help me
    Tuesday, March 20, 2018 12:08 AM

All replies

  • https://developer.mozilla.org/en-US/docs/Web/API/Element

    You should be able to address the Elelment.Id and Eleliment.Classname.

    You see it being done in the loop.

    https://stackoverflow.com/questions/16181773/loop-over-every-htmlelement-on-a-page-in-a-webbrowser-control

    Since a collection of elements are being retuned, you can use Linq to query the elements and get an object retuned.

     dim elm = (From a in webBrowser1.Document.All

                       Where a.Id = "username" and a.Classname = "input4" select a)SingleOrDefault()

    If not IsNothing(elm) then

      dim id = elm.ID

      dim classname = elm.classname

    end if

    Either try the Linq statement or go into a loop to find the element wanted.

    • Proposed as answer by Reed KimbleMVP Tuesday, March 20, 2018 11:52 AM
    Tuesday, March 20, 2018 7:30 AM
  • Hi adeptdc,

    If there is same id for different TextBox, you can use Class to distinguish them.

    Like this:

    https://stackoverflow.com/questions/47502319/vb-net-webbrowser-htmlelement-getting-a-textbox-by-element-that-has-no-id

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 20, 2018 8:39 AM