Jump to content

_IEGetObjById not works all time on wordpress ??


Recommended Posts

hello everybody 

I have multi wordpress sites may increased to 200 sites

my script can create posts in the all wordpress sites 

but I'm facing so big problem!

sometimes the script detect the sites obj (using _IEGetObjById) but sometime not.

so I made a loop to oblige my script to get the obj but the problem is still existed

so the script freezing in waiting to get the objects 

note that the pages are completely loaded but it sends the error sometimes

I need to ensure getting (_IEGetObjById) to avoid getting error 

For $i = 0 To UBound($url_arr) - 1
    ;=====================================
    Do
        Local $oIE = _IECreate($url_arr[$i])
        _IELoadWait($oIE)
        ;-----------------------------------
        Local $title = _IEGetObjById($oIE, "title")
        Local $oText = _IEGetObjById($oIE, "content")
        Local $chkbx = _IEGetObjById($oIE, "in-category-1")
        Local $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
        Local $oSubmit = _IEGetObjById($oIE, "publish")
        ;---------------------------------------
        If Not @error Then ExitLoop
        ;Sleep(10)
        ;------------------------------
        If @error Then
            _IEAction($oIE, "refresh")
            _IELoadWait($oIE)
        EndIf
        ;----------------------------
    Until Not @error
    ;=====================================
    _IEFormElementSetValue($title, $Post_ttl)
    _IEFormElementSetValue($oText, $cntnt)
    _IEFormElementSetValue($oTag, $Tags)
    _IEAction($chkbx, "click")
    ;------------------------------------------------
    _IEAction($oSubmit, "click")
    ;------------------------------------------------
    _IELoadWait($oIE)
    _IEQuit($oIE)
Next

how to solve the problem please ?

Edited by AlienStar
Link to comment
Share on other sites

It isn't clear from your post which element you are having difficulty with. Can you elaborate?

A few suggestions --

  • I doubt that your Do...Until is working because the value of @error gets reset each time a command is executed
  • Do you really need to perform the _IECreate within your loop?
  • Your first check on @error is only going to reflect the result of the immediately prior _IEGetObjById. What if one of the prior instances failed?
Link to comment
Share on other sites

#1:

Quote
  • I doubt that your Do...Until is working because the value of @error gets reset each time a command is executed

in "do ... until" it will exit the loop if gets all objects without any error:

If Not @error Then ExitLoop

my first code was as below 

For $i = 0 To UBound($url_arr) - 1
    ;=====================================
    Local $oIE = _IECreate($url_arr[$i])
    _IELoadWait($oIE)
    ;-----------------------------------
    Local $title = _IEGetObjById($oIE, "title")
    Local $oText = _IEGetObjById($oIE, "content")
    Local $chkbx = _IEGetObjById($oIE, "in-category-1")
    Local $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
    Local $oSubmit = _IEGetObjById($oIE, "publish")
    ;=====================================
    _IEFormElementSetValue($title, $Post_ttl)
    _IEFormElementSetValue($oText, $cntnt)
    _IEFormElementSetValue($oTag, $Tags)
    _IEAction($chkbx, "click")
    ;------------------------------------------------
    _IEAction($oSubmit, "click")
    ;------------------------------------------------
    _IELoadWait($oIE)
    _IEQuit($oIE)
Next

but sometimes it send me an object error so I get 0 when I check each one while error occurs 

MsgBox(0,"Error", "$title: " & IsObj($title) &@CRLF & _
                "$oText: " & IsObj($oText) &@CRLF & _
                "$chkbx: " & IsObj($chkbx) &@CRLF & _
                "$oSubmit: " & IsObj($oSubmit)&@CRLF & _
                "$oTag: " & IsObj($oTag) )

that's why I made "do loop" to ensure get all objects without errors  

 

#2:

Quote

Do you really need to perform the _IECreate within your loop?

yes of course because I have many websites to create the post in each one

 

#3:

Quote
  • Your first check on @error is only going to reflect the result of the immediately prior _IEGetObjById. What if one of the prior instances failed?

if one of the objects (that I need to get) make an error I put this condition :

If @error Then
    _IEAction($oIE, "refresh")
    _IELoadWait($oIE)
EndIf

so when it ensures that there is no error it will move to the next step:

_IEFormElementSetValue($title, $Post_ttl)
_IEFormElementSetValue($oText, $cntnt)
_IEFormElementSetValue($oTag, $Tags)
_IEAction($chkbx, "click")
;------------------------------------------------
_IEAction($oSubmit, "click")
;------------------------------------------------
_IELoadWait($oIE)
_IEQuit($oIE)

 

Edited by AlienStar
Link to comment
Share on other sites

Sorry, but you need to research / understand the way @error works because you are mistaken. As I said before --

Quote

Your first check on @error is only going to reflect the result of the immediately prior _IEGetObjById. What if one of the prior instances failed?

From the help file entry for SetError --

Quote

Remarks

When entering a function @error is set to 0. Unless SetError() is called, then @error will remain 0 when the function ends. This means that in order for @error to be set after a function, it must be explicitly set. This also means you may need to backup the status of @error in a variable if you are testing it in a While-WEnd loop.

So the line

If Not @error Then ExitLoop

will only be triggered if this line fails --

Local $oSubmit = _IEGetObjById($oIE, "publish")

If this line succeeds but any of the prior lines fail, @error will still be zero.

Link to comment
Share on other sites

First, you do not understand how @error is working.  Like Danp2 said it gets reset after each statement.  So in your case, you only check for this single statement :

Local $oSubmit = _IEGetObjById($oIE, "publish")

Not any of the previous ones.

Second, it is not necessary to use _IECreate at each iteration of the loop.  You could use _IENavigate instead, would make your script perform way faster...

Link to comment
Share on other sites

2 hours ago, Danp2 said:

Sorry, but you need to research / understand the way @error works because you are mistaken. As I said before --

From the help file entry for SetError --

So the line

If Not @error Then ExitLoop

will only be triggered if this line fails --

Local $oSubmit = _IEGetObjById($oIE, "publish")

If this line succeeds but any of the prior lines fail, @error will still be zero.

now it's clear more 👍

 

2 hours ago, Nine said:

First, you do not understand how @error is working.  Like Danp2 said it gets reset after each statement.  So in your case, you only check for this single statement :

Local $oSubmit = _IEGetObjById($oIE, "publish")

Not any of the previous ones.

Second, it is not necessary to use _IECreate at each iteration of the loop.  You could use _IENavigate instead, would make your script perform way faster...

good idea I'll do  certainly :)

2 hours ago, Danp2 said:

But it shouldn't be inside your Do...Until.

mmmm OK 👍

 

Link to comment
Share on other sites

? a possible quick way to go (not tested):

Local $oIE = _IECreate() ; create the $oIE only one time
Local $iError, $title, $oText, $chkbx, $oTag, $oSubmit ; create the variables just once outside the loop

For $i = 0 To UBound($url_arr) - 1
    ;=====================================
    _IENavigate($oIE, $url_arr[$i])     ; load the next [$i] page
    _IELoadWait($oIE)
    While True ; Try to get all objects without errors
        ;-----------------------------------
        $iError = 0
        $title = _IEGetObjById($oIE, "title")
        $iError += @error
        $oText = _IEGetObjById($oIE, "content")
        $iError += @error
        $chkbx = _IEGetObjById($oIE, "in-category-1")
        $iError += @error
        $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
        $iError += @error
        $oSubmit = _IEGetObjById($oIE, "publish")
        $iError += @error
        ;---------------------------------------
        If Not $iError Then ExitLoop ; all above without any error?
        ;Sleep(10)
        ;------------------------------
        _IEAction($oIE, "refresh")
        _IELoadWait($oIE)
        ;----------------------------
    WEnd
    ;=====================================
    _IEFormElementSetValue($title, $Post_ttl)
    _IEFormElementSetValue($oText, $cntnt)
    _IEFormElementSetValue($oTag, $Tags)
    _IEAction($chkbx, "click")
    ;------------------------------------------------
    _IEAction($oSubmit, "click")
    ;------------------------------------------------
    _IELoadWait($oIE)
    ; _IEQuit($oIE)
Next

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

1 hour ago, Chimp said:

? a possible quick way to go (not tested):

Local $oIE = _IECreate() ; create the $oIE only one time
Local $iError, $title, $oText, $chkbx, $oTag, $oSubmit ; create the variables just once outside the loop

For $i = 0 To UBound($url_arr) - 1
    ;=====================================
    _IENavigate($oIE, $url_arr[$i])     ; load the next [$i] page
    _IELoadWait($oIE)
    While True ; Try to get all objects without errors
        ;-----------------------------------
        $iError = 0
        $title = _IEGetObjById($oIE, "title")
        $iError += @error
        $oText = _IEGetObjById($oIE, "content")
        $iError += @error
        $chkbx = _IEGetObjById($oIE, "in-category-1")
        $iError += @error
        $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
        $iError += @error
        $oSubmit = _IEGetObjById($oIE, "publish")
        $iError += @error
        ;---------------------------------------
        If Not $iError Then ExitLoop ; all above without any error?
        ;Sleep(10)
        ;------------------------------
        _IEAction($oIE, "refresh")
        _IELoadWait($oIE)
        ;----------------------------
    WEnd
    ;=====================================
    _IEFormElementSetValue($title, $Post_ttl)
    _IEFormElementSetValue($oText, $cntnt)
    _IEFormElementSetValue($oTag, $Tags)
    _IEAction($chkbx, "click")
    ;------------------------------------------------
    _IEAction($oSubmit, "click")
    ;------------------------------------------------
    _IELoadWait($oIE)
    ; _IEQuit($oIE)
Next

 

thanks my friend I'll try :)

Link to comment
Share on other sites

I would suggest you to investigate on the WordPress side. 

If your website is not generated always the same way. You could just send a refresh to get the element next time. 

14 hours ago, AlienStar said:

note that the pages are completely loaded but it sends the error sometimes

With that, I understand that your page are all same and sometimes the object is here sometimes not.  That is why.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

7 hours ago, caramen said:

I would suggest you to investigate on the WordPress side. 

If your website is not generated always the same way. You could just send a refresh to get the element next time. 

With that, I understand that your page are all same and sometimes the object is here sometimes not.  That is why.

I'm working so hard to detect the problem 

Link to comment
Share on other sites

Global $title, $oText, $chkbx, $oTag, $oSubmit, $oIE

For $i = 0 To UBound($url_arr) - 1
    $oIE = _IECreate($url_arr[$i])
    _RefreshPageIfError ($oIE)

    _IEFormElementSetValue($title, $Post_ttl)
    _IEFormElementSetValue($oText, $cntnt)
    _IEFormElementSetValue($oTag, $Tags)
    _IEAction($chkbx, "click")
    _IEAction($oSubmit, "click")
    _IEQuit($oIE)

    _ResetVar ()
Next


Func _RefreshPageIfError ($oIE)
    _IELoadWait($oIE)

    $title = _IEGetObjById($oIE, "title")
        If @error Then
            _IELoadWait($oIE)
            $title = _IEGetObjById($oIE, "title")
        EndIf

    $oText = _IEGetObjById($oIE, "content")
        If @error Then
            _IELoadWait($oIE)
            $oText = _IEGetObjById($oIE, "content")
        EndIf

    $chkbx = _IEGetObjById($oIE, "in-category-1")
        If @error Then
            _IELoadWait($oIE)
            $chkbx = _IEGetObjById($oIE, "in-category-1")
        EndIf

    $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
        If @error Then
            _IELoadWait($oIE)
            $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
        EndIf

    $oSubmit = _IEGetObjById($oIE, "publish")
        If @error Then
            _IELoadWait($oIE)
            $oSubmit = _IEGetObjById($oIE, "publish")
        EndIf
EndFunc

Func _ResetVar ()
    $title =    Null
    $oText =    Null
    $chkbx =    Null
    $oTag =     Null
    $oSubmit=   Null
EndFunc

Or

Global $title, $oText, $chkbx, $oTag, $oSubmit, $oIE

For $i = 0 To UBound($url_arr) - 1
    
    $oIE = _IECreate($url_arr[$i])
    _RefreshPageIfError ($oIE)

    _IEFormElementSetValue($title, $Post_ttl)
    _IEFormElementSetValue($oText, $cntnt)
    _IEFormElementSetValue($oTag, $Tags)
    _IEAction($chkbx, "click")
    _IEAction($oSubmit, "click")
    _IEQuit($oIE)

    _ResetVar ()
Next

Func _RefreshPageIfError ($oIE)
    _IELoadWait($oIE)
    Do
        $title = _IEGetObjById($oIE, "title")
        $oText = _IEGetObjById($oIE, "content")
        $chkbx = _IEGetObjById($oIE, "in-category-1")
        $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
        $oSubmit = _IEGetObjById($oIE, "publish")

        _IELoadWait($oIE)

        _ResetVar ()
    Until $title <> 3 Or $title <> 7 And $oText <> 3 Or $oText <> 7 And $chkbx <> 3 Or $chkbx <> 7  And $oTag <> 3 Or $oTag <> 7 And $oSubmit <> 3 Or $oSubmit <> 7
EndFunc

Func _ResetVar ()
    $title =    Null
    $oText =    Null
    $chkbx =    Null
    $oTag =     Null
    $oSubmit=   Null
EndFunc

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

furthermore, even if he intended to use _IEaction instead, there is also another problem, and that is, by "refreshing" the page, you lose all references to the objects you created before the refresh .....

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

4 minutes ago, Danp2 said:

Where do you come up with these crazy incorrect syntax examples? 😲🙄

Ops fail copy past thx it's corrected, 😅

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

2 minutes ago, Chimp said:

furthermore, even if he intended to use _IEaction instead, there is also another problem, and that is, by "refreshing" the page, you lose all references to the objects you created before the refresh .....

The logic provided work with that in the second example. 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Quote
Func _RefreshPageIfError ($oIE)
    _IELoadWait($oIE)
    Do
        $title = _IEGetObjById($oIE, "title")
        $oText = _IEGetObjById($oIE, "content")
        $chkbx = _IEGetObjById($oIE, "in-category-1")
        $oTag = _IEGetObjById($oIE, "new-tag-post_tag")
        $oSubmit = _IEGetObjById($oIE, "publish")

        _IELoadWait($oIE)

        _ResetVar ()
    Until $title <> 3 Or $title <> 7 And $oText <> 3 Or $oText <> 7 And $chkbx <> 3 Or $chkbx <> 7  And $oTag <> 3 Or $oTag <> 7 And $oSubmit <> 3 Or $oSubmit <> 7
EndFunc

Func _ResetVar ()
    $title =    Null
    $oText =    Null
    $chkbx =    Null
    $oTag =     Null
    $oSubmit=   Null
EndFunc

Not sure how you expect this to work either.

1. _IEGetObjById sets @error to 3 / 7, not the returned value

2. Even if the above wasn't true, you reset the value of the variables to Null at the bottom of the loop so there's no way any of them will equal 3 or 7

Link to comment
Share on other sites

maybe by refreshing the page or something else there is something wrong happened 

NOW, when the loop reached to the 13th item array (websites array) the browser send me this message 

"A problem with a webpage caused IE 11 to close and reopen the tab"

then the script is still waiting the browser but no answer, and the browser is completely loaded and do nothing .

As if the browser detach my script 

the problem becomes bigger :(

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...