Results 1 to 10 of 10

Thread: Select value from webbrowser combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    7

    Select value from webbrowser combobox

    Hey...
    i'm trying to select value from webbrowser combobox using this method :
    Dim theother =
    (
    From X In WebBrowser1.Document.GetElementsByTagName("select").Cast(Of HtmlElement)()
    Where X.GetAttribute("name") = "expYear" Select X.GetElementsByTagName("option")
    ).FirstOrDefault

    Dim othitem = (From X In theother.Cast(Of HtmlElement)() Where X.InnerText = "2019").FirstOrDefault
    othitem.SetAttribute("selected", CStr(True))
    othitem.RaiseEvent("onchange")
    but it didn't help in my case it just changed the value but when i click register it says the the combobox value is nothing so is there any alternative method to select or click at my value ?
    Thanks for reading !

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Select value from webbrowser combobox

    Given an html dropdown control below:
    Code:
    <select aria-label="Month" name="birthday_month" id="month" title="Month" class="_5dba">
      <option value="0">Month</option>
      <option value="1">Jan</option>
     <option value="2">Feb</option>
     <option value="3">Mar</option>
     <option value="4">Apr</option>
     <option value="5">May</option>
    <option value="6">Jun</option>
    </select>
    To select the month of april, you need to set the value using SetAttribute() method.
    VB.NET Code:
    1. WebBrowser1.Document.GetElementById("month").SetAttribute("value", "4")
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    7

    Re: Select value from webbrowser combobox

    Quote Originally Posted by KGComputers View Post
    Given an html dropdown control below:
    Code:
    <select aria-label="Month" name="birthday_month" id="month" title="Month" class="_5dba">
      <option value="0">Month</option>
      <option value="1">Jan</option>
     <option value="2">Feb</option>
     <option value="3">Mar</option>
     <option value="4">Apr</option>
     <option value="5">May</option>
    <option value="6">Jun</option>
    </select>
    To select the month of april, you need to set the value using SetAttribute() method.
    VB.NET Code:
    1. WebBrowser1.Document.GetElementById("month").SetAttribute("value", "4")
    i think you didn't get it !
    the main problem is SetAttribute it doesn't help in my case , i have to select the value manually , because when i use SetAttribute it works but the website says i didn't enter any value so i need another method like click to select my value got it ?

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Select value from webbrowser combobox

    Perhaps you can include the url of the website so others can look into it.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    7

    Re: Select value from webbrowser combobox

    Quote Originally Posted by KGComputers View Post
    Perhaps you can include the url of the website so others can look into it.

    - kgc
    it will ask them for payment to continue signing up , by the way all what i want an alternative for SetAttribute is that possible using invoke member or any method else ?

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Select value from webbrowser combobox

    It is quite possible that the problem you are running into is that the owners of the site don't want you to be able to do what you are doing. What is the URL of the site?
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    7

    Re: Select value from webbrowser combobox

    Quote Originally Posted by Shaggy Hiker View Post
    It is quite possible that the problem you are running into is that the owners of the site don't want you to be able to do what you are doing. What is the URL of the site?
    no it's not possible , i had a similar problem before with textboxes i had to focus after writing my value or it will say the textboxes value = null i tried to do the same with comboboxes after using SetAttribute but it didn't work that's why i'm asking about another method to select the value from that combobox without SetAttribute , i can't provide the url because the interface will be different and it's complicated "you have to change the user agent etc" that's why i didn't provide the url in the thread because it will be kinda useless .

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Select value from webbrowser combobox

    Ok, let's be more explicit: The field you show looks like a credit card field. That makes me think that what you are trying to do is against the policy of the site, since pretty much NO site would want you to be able to automate the entry of credit card information. Therefore, they may well have taken steps to prevent you from doing what you are trying to do. That's what the URL would show.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    7

    Re: Select value from webbrowser combobox

    Quote Originally Posted by Shaggy Hiker View Post
    That's what the URL would show.
    this part of your replay was totally wrong , the other part yeah maybe but not the same as you said , not credit card filed actually , by the way let's back to our point , the main problem now is SetAttribute is there any alternative way else to pick value from webbrowser combobox ?

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Select value from webbrowser combobox

    No, the main problem is that, if this action is against the policy of the site in question, then it is also against the AUP of this site, which you agreed to when you signed up. Your being unusually coy about what the site is, and suggesting that what you are doing might be something the site doesn't want you to do, is enough to close the thread. If you feel that what you are doing is acceptable to the site in question, then feel free to PM the URL to me.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width