Jump to content

Recommended Posts

Posted (edited)

Hi Guys, 

I want to highlight an item on my GUI: 

image.png.6457ce35cea56d9c22d6e878f77c6e21.png

 

I prepared below code:

ConsoleWrite(@CRLF & "Checkpoint 01" & @CRLF)
$sSelector = "//h1[contains(text(),'Welcome to BSS')]"

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sSelector, Default, True)
ConsoleWrite(@CRLF & "Checkpoint 02" & @CRLF)

_WD_HighlightElements($sSession, $sElement, 3) ;3 - Highlight yellow rounded box + border dotted red
If @error Then
    ConsoleWrite("Checkpoint 03 ERROR IS: " & @error & @CRLF)
EndIf
ConsoleWrite(@CRLF & "Checkpoint 04" & @CRLF)
  • Find Element --> Failed
  • Highlight Element --> Failed
Checkpoint 01
__WD_Post: URL=HTTP://127.0.0.1:5555/session/e8400313055f3e527203269ed8b79caa/elements; Data={"using":"xpath","value":"\/\/h1[contains(text(),'Welcome to BSS')]"}
__WD_Post ==> Success [0] : HTTP status = 200 ResponseText={"value":[]}
_WD_FindElement ==> No match [8] : Parameters:   Strategy=xpath   Selector=//h1[contains(text(),'Welcome to BSS')]   StartNodeID=Default   Multiple=True   ShadowRoot=Default

Checkpoint 02
__WD_Post: URL=HTTP://127.0.0.1:5555/session/e8400313055f3e527203269ed8b79caa/execute/sync; Data={"script":"arguments[0].style='border: 2px dotted red; background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":""}]}
__WD_Post ==> No match [8] : HTTP status = 404 ResponseText={"value":{"error":"stale element reference","message":"stale element reference: element is not attached to the page document\n  (Session info: chrome=99.0.4844.84)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00AD9943+2595139]\n\tOrdinal0 [0x00A6C9F1+2148849]\n\tOrdinal0 [0x00964528+1066280]\n\tOrdinal0 [0x00966E04+1076740]\n\tOrdinal0 [0x00966CBE+1076414]\n\tOrdinal0 [0x0096763A+1078842]\n\tOrdinal0 [0x009BC529+1426729]\n\tOrdinal0 [0x009AB9EC+1358316]\n\tOrdinal0 [0x009BBAF2+1424114]\n\tOrdinal0 [0x009AB806+1357830]\n\tOrdinal0 [0x00986086+1204358]\n\tOrdinal0 [0x00986F96+1208214]\n\tGetHandleVerifier [0x00C7B232+1658114]\n\tGetHandleVerifier [0x00D3312C+2411516]\n\tGetHandleVerifier [0x00B6F261+560433]\n\tGetHandleVerifier [0x00B6E366+556598]\n\tOrdinal0 [0x00A7286B+2173035]\n\tOrdinal0 [0x00A775F8+2192888]\n\tOrdinal0 [0x00A776E5+2193125]\n\tOrdinal0 [0x00A811FC+2232828]\n\tBaseThreadInitThunk [0x74EA3D05+18]\n\t(No symbol) [0x77089732]\n\t(No symbol) [0x77089705]\n"}}
_WD_ExecuteScript ==> No match [8] : stale element reference: element is not attached to the page document
  (Session info: chrome=99.0.4844.84)
_WD_HighlightElements ==> No match [8] : Parameters:    Element=    Method=3
Checkpoint 03 ERROR IS: 8

Checkpoint 04

I'm not sure if I can use "//h1[contains(text(),'Welcome to BSS')]" or I should change h1 to * "//*[contains(text(),'Welcome to BSS')]". I don't know what h1 means, and I don't know if it's supported. How can I highlight that Welcome to BSS text?

 

 

Edited by taylansan

TY.

  • taylansan changed the title to WebDriver: I can't find an element with h1 title
  • Solution
Posted (edited)

Hi @taylansan 👋 ,

please notice ⚠ I assume such a structure:

Spoiler
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>Welcome to BSS</h1>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <div>
      <h1>Welcome to BSS</h1>
      <div>What ever</div>
    </div>
  </body>
</html>

 

you use _WD_FindElement() in the multi element way. The fifth parameter is set to true which means you want to get all occurences of the <h1> elements (with the specific text).

1. Either you change your XPath to only search the first element like

(//h1[contains(text(),'Welcome to BSS')])[1]

or 2. simply set false as fifth parameter

_WD_FindElement($sSession, $mConfig.LocatorStrategy, $sSelector, Default, False)

or 3, without the fifth parameter because the default value is false

_WD_FindElement($sSession, $mConfig.LocatorStrategy, $sSelector, Default)

... and try again 🙂 .

-----------------------------------------

⚠ In case you are searching within an iframe, you first have to enter the frame and do your locator strategy (search) their.

Func _EnterIFrame($sSelector)
    _WD_FrameEnter($sSession, _FindElement($sSelector))
EndFunc

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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
×
×
  • Create New...