Selenium if this element exists Problem

Get help with using AutoHotkey and its commands and hotkeys
User avatar
rizwan4season
Posts: 11
Joined: 13 Nov 2020, 08:37

Selenium if this element exists Problem

24 Dec 2020, 12:06

Code: Select all

click:
driver.findElementByID("imgbtnLogin").click

Exists := driver.findElementByID("lblError").Attribute("innerText");When disappear this line from Chorme Web page it's give me error  
MSG_ERROR := InStr(Exists,"000")

if(MSG_ERROR > 0)
{
	goto,click
}
else
{
	msgbox,done
}
[Mod edit: [code][/code] tags added.]
User avatar
Xtra
Posts: 2060
Joined: 02 Oct 2015, 12:15

Re: Selenium if this element exists Problem

24 Dec 2020, 16:16

See: Try Catch

Example:

Code: Select all

click:
driver.findElementByID("imgbtnLogin").click

try
{
	Exists := driver.findElementByID("lblError").Attribute("innerText")
	MSG_ERROR := InStr(Exists,"000")
	if (MSG_ERROR > 0)
		goto,click
}
catch
    msgbox,done

return
If the lblError element exists you can probably just shorten the code to:

Code: Select all

click:
driver.findElementByID("imgbtnLogin").click

try
{
	Exists := driver.findElementByID("lblError").Attribute("innerText")
	goto,click
}
catch
    msgbox,done

return
or

Code: Select all

click:
Loop
{
	driver.findElementByID("imgbtnLogin").click
	try
		Exists := driver.findElementByID("lblError").Attribute("innerText")
	catch
		break
	Sleep 500
}
return
HTH
User avatar
rizwan4season
Posts: 11
Joined: 13 Nov 2020, 08:37

Re: Selenium if this element exists Problem

25 Dec 2020, 00:37

Thanks Xra it's Working
Kindly i have a one more question
When this Script Fully load and run Chorme automate Closed i am Still not understand
When i use driver:= ComObjCreate("Selenium.WebDriver") why Chorme Closed....?

Return to “Ask For Help”

Who is online

Users browsing this forum: ark, Google [Bot], Spawnova and 37 guests