Jump to content

IE table and text values


Recommended Posts

Hi all,

I am trying to scrape values from a web page that has a table of controls in it like text, textarea, select-one controls and such. This all works great except for one problem. When a control is of type text or textarea and I try get the value property of the control, I get the correct value in all cases but one. If value = "" I get back "0" in my script variable:

$tempObj = _IEGetObjById ($ieObj, $tempId)

$tempValue = $tempObj.value

if the webpage actually has value="" for the control with Id $tempId, $tempValue will end up with the value of "0" not "". Thus I can't tell if the user of the page actually left the control blank or explicitly entered a 0. Has anyone else had this problem? Am I doing something wrong? Is there a way to discern a "" entry from a "0" entry?

Thanks for any help!!

BMac

Link to comment
Share on other sites

You need to use

$tempValue = String($tempObj.value)

Then if it is empty you'll get "" and if it is 0 you get "0".

AutoIt uses variants instead of strongly typed variables. It doesn't know that you expect a string response and ends up converting it to a numeric. String() forces the result you want.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

You need to use

$tempValue = String($tempObj.value)

Then if it is empty you'll get "" and if it is 0 you get "0".

AutoIt uses variants instead of strongly typed variables. It doesn't know that you expect a string response and ends up converting it to a numeric. String() forces the result you want.

Dale

Already tried that...same result.

BMac

Link to comment
Share on other sites

Already tried that...same result.

BMac

I have a hard time accepting that. Please show your work -- provide a website and code that demonstrates this. I deal with this all the time in IE.au3

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I have a hard time accepting that. Please show your work -- provide a website and code that demonstrates this. I deal with this all the time in IE.au3

Dale

Okay...how about this:

#include "IE.au3"
; Create an IE instance
$ieObj = _IECreate("C:\Automation\bogus.html", 0, 1, 1, 1)
_IELoadWait ($ieObj)
$tempObj = _IEGetObjById ($ieObj, "bogusValue1")
$tempString1 = String($tempObj.value)
$tempObj = _IEGetObjById ($ieObj, "bogusValue2")
$tempString2 = String($tempObj.value)
MsgBox(0, "Values", $tempString1 & "   " & $tempString2)

Output comes up "0 0"...I expected just one zero.

Here is HTML:

<html>
  <head>
    <title>bogus</title>
  </head>
  <body>
    <input name="bogusValue1" type="text" class="inputField" size="15" id="bogusValue1" value="">
    <input name="bogusValue2" type="text" class="inputField" size="15" id="bogusValue2" value="0">
  </body>
</html>

Bug yes? Again, why is AutoIt assuming a text field to be a numeric value in the first place?

BMac

Link to comment
Share on other sites

Thanks for the example -- I stand corrected. My dealings with this in IE.au3 are slightly different.

As you have discovered, when the field is NULL, the .value property returns an integer 0 rather than a null string.

You can file a bug if you choose, but I have my doubts that the AutoIt behavior will change.

Your workaround will be to test the data type of the return value using either isInt or isString and treat it accordingly -- If isInt($value1) then value1 = ""

Here is a self-contained version of the example you provided:

#include <IE.au3>

$oIE = _IECreate()

$sHTML = "" 
$sHTML &= "<html>"
$sHTML &= "  <head>"
$sHTML &= "    <title>bogus</title>"
$sHTML &= "  </head>"
$sHTML &= "  <body>"
$sHTML &= "    <input type='text' id='Value1' value=''>"
$sHTML &= "    <input type='text' id='Value2' value='0'>"
$sHTML &= "  </body>"
$sHTML &= "</html>"

_IEDocWriteHTML($oIE, $sHTML)

$oInput1 = _IEGetObjById ($oIE, "Value1")
$value1 = $oInput1.value
$oInput2 = _IEGetObjById ($oIE, "Value2")
$value2 = $oInput2.value

$sDataType1 = "String "
$sDataType2 = "String "

If isInt($value1) Then $sDataType1 = "Integer "
If isInt($value2) Then $sDataType2 = "Integer "

MsgBox(0, "Values", _
        "Value1: " & $sDataType1 & $value1 & @CR & _
        "Value2: " & $sDataType2 & $value2)

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

>Thanks for the example -- I stand corrected. My dealings with this in IE.au3 are slightly different.

Well, glad I am not crazy!

>As you have discovered, when the field is NULL, the .value property returns an integer 0 rather than a null string.

>You can file a bug if you choose, but I have my doubts that the AutoIt behavior will change.

That seems odd...but I don't really care if I have a workaround.

>Your workaround will be to test the data type of the return value using either isInt or isString and treat it accordingly -- If isInt($value1) >then value1 = ""

Worked like a charm! Thanks a million, I can't tell you how much hassle that saved me!

BMac

Link to comment
Share on other sites

This is actually an opportunity for me to add some value in _IEFormElementGetValue -- so long as I cannot come up with a scenario where an integer is a valid return value, I will do this check and string conversion in a future release of IE.au3...

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...