Capel Posted March 16, 2010 Share Posted March 16, 2010 I want to change the background color of an IE form element. $oForm = _IEFormGetObjByName ($oIE, "form1") $oElems = _IEFormElementGetCollection ($oForm) For $oElem in $oElems if StringInStr(StringRight($oElem.id,9),"name_name") > 0 Then $oTboxName = $oElem ; here I want to find the $oElem parent form and change its background color EndIf Next So I need to go up the DOM to find the parent <form> and then set its background color. How would I do this? Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 16, 2010 Share Posted March 16, 2010 In your example, the parent is $oForm. Why would you need to go looking for it? As for the style attribute backgroundColor: #include <IE.au3> $oIE = _IE_Example("Form") $oForm = _IEFormGetObjByName($oIE, "ExampleForm") $iColor = $oForm.style.backgroundColor ; 0 = transparent (default) ConsoleWrite("$iColor = " & $iColor & @LF) $oForm.style.backgroundColor = 0xFFFF00 ; Yellow $iColor = $oForm.style.backgroundColor ConsoleWrite("$iColor = " & $iColor & @LF) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Capel Posted March 16, 2010 Author Share Posted March 16, 2010 Sorry, I stated the problem incorrectly. I'm looking for a specific <table> on the page and want to change the background color of just that table. In fact I know the table's class. Here is the HTML of the table: <table class="controlContainer" cellSpacing="0" cellPadding="0" border-top border="0"> There are actually 3 tables on the page with this class and I want to change the background color of all 3. Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 16, 2010 Share Posted March 16, 2010 OK... #include <IE.au3> $oIE = _IE_Example("Table") $co1Tables = _IETableGetCollection($oIE) For $oTable In $co1Tables $iColor = $oTable.style.backgroundColor ; 0 = transparent (default) ConsoleWrite("$iColor = " & $iColor & @LF) $oTable.style.backgroundColor = 0xFFFF00 ; Yellow $iColor = $oTable.style.backgroundColor ConsoleWrite("$iColor = " & $iColor & @LF) Next Yellow tables. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Capel Posted March 16, 2010 Author Share Posted March 16, 2010 Psalty, this is great! How do I search for just the 3 tables I want? Just the ones whose class = controlContainer There are 80 tables on the page! Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 16, 2010 Share Posted March 16, 2010 C'mon dude, show some effort! Get the collection, loop through it testing each one for your conditions. The property you're looking for is .className. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Capel Posted March 16, 2010 Author Share Posted March 16, 2010 C'mon dude, show some effort! I hear you. Yes I know how to loop thru them, but I did not know the prop name. "Class" did not work. Where are the properties documented?Thanks for your help! Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 16, 2010 Share Posted March 16, 2010 MSDN: About the W3C Document Object ModelGoogle is your friend (unless you're in China). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Capel Posted March 17, 2010 Author Share Posted March 17, 2010 (edited) Using Psalty's method: For $oTable In $oTables $oTable.style.backgroundColor = 0xFFFF00 ; Yellow Next will set all of the table backgrounds on the page to yellow. However, when I find just the tables I want, it does not work. For $oTable In $oTables If String($oTable.className) = "controlContainer" Then $oTable.style.backgroundColor = 0xFFFF00 ; Yellow EndIf Next What am I missing here? [Edit to add] The filter on "controlContainer" does work and find the 3 tables I'm looking for. Edited March 17, 2010 by Capel Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 17, 2010 Share Posted March 17, 2010 Can't replicate your problem. This sets the style of the second table only to "controlContainer", then uses that to ID the one for yellow background: #include <IE.au3> $oIE = _IE_Example("Table") $oTable = _IETableGetCollection($oIE, 1) ; second table $oTable.className = "controlContainer" $co1Tables = _IETableGetCollection($oIE) For $oTable In $co1Tables If ($oTable.className & "") = "controlContainer" Then $iColor = $oTable.style.backgroundColor ; 0 = transparent (default) ConsoleWrite("$iColor = " & $iColor & @LF) $oTable.style.backgroundColor = 0xFFFF00 ; Yellow $iColor = $oTable.style.backgroundColor ConsoleWrite("$iColor = " & $iColor & @LF) Else ConsoleWrite("Skipped one table..." & @LF) EndIf Next Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Capel Posted March 17, 2010 Author Share Posted March 17, 2010 Psalty, what version are you running. I'm using 3.3.6. Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 17, 2010 Share Posted March 17, 2010 (edited) Well, actually, I didn't realize until you asked that this machine wasn't updated. So I was checking against 3.3.4.0 Prod.However, I just updated this box to 3.3.6.0 Prod and it still works fine: >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Program Files\AutoIt3\Scripts\Test1.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>15:30:08 Starting AutoIt3Wrapper v.2.0.1.22 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3 CPU:X86 OS:X86)>Running AU3Check (1.54.19.0) from:C:\Program Files\AutoIt3+>15:30:08 AU3Check ended.rc:0>Running:(3.3.6.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test1.au3" Skipped one table...$iColor = 0$iColor = #ffff00+>15:30:16 AutoIT3.exe ended.rc:0>Exit code: 0 Time: 10.135 Edited March 17, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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