MorganaFreeman Posted March 12, 2018 Share Posted March 12, 2018 Hey guys, I'm quite a bit confused right now as I'm encountering a problem I can't solve. Is it possible to compare the value of a checkbox with the text in the url? For example : URL: www.example.com/admin/categories/.php?page=example&path=example2 On this site, I have the names of several products. * For each product there is a checkbox. * The name of each product is a link * If I click on one of those names, a menu opens. I can't use it tho, because I need to activate the checkbox first. - For example to move the Product to another Category Let's say, there's a product called "Example Product 1" Now I click on this link by _IELinkClickByText($oIE, "Example Product 1") After doing so, the URL changes to : www.example.com/admin/categories/.php?page=example&path=example2&ID=98765 but I'm still on the same site as before, with all the products and the checkboxes. Now all of those Checkboxes have specific Values. For example : Checkbox1 Value 12345 Checkbox2 Value 98765 Checkbox3 Value 456987 As you can see, the ID in the URL fits with one of those Checkboxes. Is it possible to automatically check the checkbox fitting to the ID in the URL? Like on this example, check Checkbox2 since the Value is the same as the ID in the url? Can't find a way to make this work. Kind regards and thanks in advance! Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 12, 2018 Author Share Posted March 12, 2018 My Idea is something like this : Get the URL as a variable : $Link_Artikel = _IEPropertyGet ($oIE, "locationurl") So $Link_Artikel would have the value www.example.com/admin/categories/.php?page=example&path=example2&ID=98765 Those links are always ending with "&ID=number" . Now I'd like to extract the "number" behind the &ID= and I just can't figure out how I do that. I could create a new variable then like $CheckboxID = (_Func_To_Extract_ID) Then I could compare this $CheckboxID to the checkboxes with _IEFormElementGetValue. But I just can't figure out how to get the ID extracted Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 12, 2018 Author Share Posted March 12, 2018 The Name of the Checkbox is always : multi_products[], they only differ by value So I'd go by this : expandcollapse popupFunc _Compare_Checkbox $oForm = _IEGetObjById($oIE, "multi_action_form") $link_artikel = _IEPropertyGet ($oIE, "locationurl") $link_id = _ExtractID_from_URL() $oCheckArticle = _IEFormElementGetObjByName($oForm, "multi_products[]") $check_value = _IEFormElementGetValue($oCheckArticle) If $Link__ID = $check_value then ;check the box EndIf EndFunc Func _ExtractID_from_URL() ;I have no clue how to do this EndFunc Something like this should work imo, but I'm kinda stuck on it. Trying to take a deeper look into stringinstring right now Link to comment Share on other sites More sharing options...
Subz Posted March 12, 2018 Share Posted March 12, 2018 Can you post some of the source code with the checkbox and value? Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 12, 2018 Author Share Posted March 12, 2018 Sure. The checkbox sits in a Table with the other elements of the Article. <!-- This is one of the tables --> <tr class="dataTableRow" style="cursor: pointer;" onmouseover="this.className='dataTableRowOver';this.style.cursor='pointer'" onmouseout="this.className='dataTableRow'"> <td class="categories_view_data"> <!-- This is the Checkbox --> <input name="multi_products[]" class="ChkBox" type="checkbox" value="17226"><em> </em> </td> Is this enough ? Link to comment Share on other sites More sharing options...
Subz Posted March 12, 2018 Share Posted March 12, 2018 So you could use something like (untested): Local $sLink_Artikel = _IEPropertyGet ($oIE, "locationurl") Local $aLink_Artikel = StringSplit($sLink_Artikel, "=") Local $iLink_Artikel = $aLink_Artikel[$aLink_Artikel[0]] Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassName = "ChkBox" Then If $oInput.Value = $iLink_Artikel Then _IEAction($oInput, "click") EndIf Next EndIf MorganaFreeman 1 Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 12, 2018 Author Share Posted March 12, 2018 Thanks a lot Subz, that worked! Func _Kategorien() $Artikellink = $Artikelname _IELinkClickByText($oIE, $Artikelname) Local $sLink_Artikel = _IEPropertyGet ($oIE, "locationurl") Local $aLink_Artikel = StringSplit($sLink_Artikel, "=") Local $iLink_Artikel = $aLink_Artikel[$aLink_Artikel[0]] Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassName = "ChkBox" Then If $oInput.Value = $iLink_Artikel Then _IEAction($oInput, "click") EndIf Next EndIf EndFunc Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 14, 2018 Author Share Posted March 14, 2018 Facing another Problem right now. I have a few other checkboxes like this : <input type="checkbox" name="dest_cat_ids[]" value="380" class="ChkBox"> <input type="checkbox" name="dest_cat_ids[]" value="150" class="ChkBox"> They are in the same form as the boxes in the problem above. I've tried to click them by value , like this : expandcollapse popupFunc _Kategorien() $Artikellink = $Artikelname _IELinkClickByText($oIE, $Artikelname) Local $sLink_Artikel = _IEPropertyGet ($oIE, "locationurl") Local $aLink_Artikel = StringSplit($sLink_Artikel, "=") Local $iLink_Artikel = $aLink_Artikel[$aLink_Artikel[0]] Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassName = "ChkBox" Then If $oInput.Value = $iLink_Artikel Then _IEAction($oInput, "click") EndIf Next EndIf _Click_Kopieren() EndFunc Func _Click_Kopieren() $oButtons = _IETagnameGetCollection($oIE, "input") For $oButton in $oButtons If String($oButton.value) = "Kopieren" Then _IEAction($oButton, "click") ExitLoop EndIf Next _KategorienAuswahl() EndFunc Func _KategorienAuswahl() _Check_Kategorie() Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassNameName = "ChkBox" Then If $oInput.Value = $CheckKategorie Then _IEAction($oInput, "click") EndIf Next EndIf EndFunc Func _Check_Kategorie() ; For example, when $google2 = Deckenleuchte and $Material = "Metall" then I want to check the box with the value 150 IF $google2 = "Deckenleuchte" AND $Material = "Metall" Then $CheckKategorie = 150 EndIf EndFunc But I can't get it to work. Could you might point out my mistake so I can find a way to solve this? Thanks in advance! Link to comment Share on other sites More sharing options...
Subz Posted March 14, 2018 Share Posted March 14, 2018 What is "Kopieren"? I can't see any difference between the first input and the second input except for the name but that shouldn't be an issue, can you post a full form example? Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 14, 2018 Author Share Posted March 14, 2018 "Kopieren" is the value of the button I want to click, this is working. The only thing not working is the following code : Func _KategorienAuswahl() _Check_Kategorie() Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassNameName = "ChkBox" Then If $oInput.Value = $CheckKategorie Then _IEAction($oInput, "click") EndIf Next EndIf EndFunc Here's the form : <form name="multi_action_form" action="---current url---" method="post" onsubmit="javascript:return CheckMultiForm()"> it's inside a table : <table class="tableBody"> <tbody><tr> Inside this form is another table with the checkboxes I want to check : <td class="infoBoxContent"> <input type="checkbox" name="dest_cat_ids[]" value="356" class="ChkBox"><em> </em><font size="1">Hersteller</font><br> <input type="checkbox" name="dest_cat_ids[]" value="361" class="ChkBox"><em> </em><font size="1"> Albert</font><br> <input type="checkbox" name="dest_cat_ids[]" value="359" class="ChkBox"><em> </em><font size="1"> Anta</font><br> <input type="checkbox" name="dest_cat_ids[]" value="360" class="ChkBox"><em> </em><font size="1"> Artemide</font><br> <input type="checkbox" name="dest_cat_ids[]" value="362" class="ChkBox"><em> </em><font size="1"> B+M Leuchten</font><br> <input type="checkbox" name="dest_cat_ids[]" value="364" class="ChkBox"><em> </em><font size="1"> B-Leuchten</font><br> etc.. And I'm having trouble accessing those checkboxes. Link to comment Share on other sites More sharing options...
Subz Posted March 14, 2018 Share Posted March 14, 2018 Can you try replacing: If $oInput.ClassNameName = "ChkBox" Then If $oInput.Value = $CheckKategorie Then _IEAction($oInput, "click") EndIf With If $oInput.ClassName = "ChkBox" Then If $oInput.Value = $iLink_Artikel Then $oInput.Checked = True EndIf Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 14, 2018 Author Share Posted March 14, 2018 Unfortunally this doesn't work. I tried it without the variable, so I can see if it works with a fix value but it doesn't. I used : If $oInput.ClassName = "ChkBox" Then If $oInput.Value = 150 Then $oInput.Checked = True EndIf Link to comment Share on other sites More sharing options...
Subz Posted March 14, 2018 Share Posted March 14, 2018 Can you run within Scite and tell us if you're getting any errors, I've written a temporary html file with your code above and it works fine for me. Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 14, 2018 Author Share Posted March 14, 2018 That's the weird thing. there isn't any error. I'll check if the checkboxes are sitting in some kind of iframe now and give you feedback later! Link to comment Share on other sites More sharing options...
Danp2 Posted March 14, 2018 Share Posted March 14, 2018 Try adding a ConsoleWrite statement so that you can determine which elements are being found / processed. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 15, 2018 Author Share Posted March 15, 2018 Things I tried so far : expandcollapse popupFunc _KategorienAuswahl() $oForm = _IEFormElementGetObjByName ($oIE, "multi_action_form") $oCheck = _IEFormElementGetObjByName ($oForm, "dest_cat_ids[]") If $oCheck.Value = 356 Then $oCheck.Checked = True EndFunc Func _KategorienAuswahl() $oForm = _IEFormElementGetObjByName ($oIE, "multi_action_form") $oCheck = _IEFormElementGetObjByName ($oForm, "dest_cat_ids[]") If String($oCheck.value) = "356" Then _IEAction($oCheck, "click") EndIf EndFunc Func _KategorienAuswahl() $oForm = _IEFormElementGetObjByName ($oIE, "multi_action_form") $oCheck = _IEFormElementGetObjByName ($oForm, "dest_cat_ids[]") If ($oCheck.value) = 356 Then _IEAction($oCheck, "click") EndIf EndFunc Func _KategorienAuswahl() $oChecks = _IETagnameGetCollection($oIE, "input") For $oCheck in $oChecks If String($oCheck.value) = "356" Then _IEAction($oCheck, "click") ExitLoop EndIf Next EndFunc Func _KategorienAuswahl() $oChecks = _IETagnameGetCollection($oIE, "input") For $oCheck in $oChecks If ($oCheck.value) = 356 Then _IEAction($oCheck, "click") ExitLoop EndIf Next EndFunc Func _KategorienAuswahl() Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassName = "ChkBox" Then If $oInput.Value = 356 Then $oInput.Checked = True EndIf Next EndIf EndFunc Func _KategorienAuswahl() Local $oTable = _IETagNameGetCollection ($oIE, "table") If String($oTable.className) = "infoBoxContent" Then Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassName = "chkBox" Then If $oInput.Value = 356 Then $oInput.Checked = True EndIf Next EndIf EndIf EndFunc None of those seem to be working and I have absolutely no Idea what else to do. Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 15, 2018 Author Share Posted March 15, 2018 So this is the HTML code. It's not sitting in an iframe, it sits in the Table "infoBoxContent" of the Form "multi_action_form". So I see no reason why it doesn't work.. Link to comment Share on other sites More sharing options...
MorganaFreeman Posted March 15, 2018 Author Share Posted March 15, 2018 Okay I made it with this : Func _KategorienAuswahl() Local $oInputs = _IETagNameGetCollection($oIE, "input") If IsObj($oInputs) Then For $oInput In $oInputs If $oInput.ClassName = "ChkBox" Then If $oInput.Value = 356 Then _IEAction($oInput, "click") EndIf Next EndIf EndFunc My problem was, that I didn't put an _IELoadWait in the func which called _KategorienAuswahl() ! It was so simple... thanks for all of your help! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now