Jump to content

Recommended Posts

Posted (edited)

I am using web driver and xpaths to automate chrome. 

I am able to edit everything I need to until I get these pop ups. Then when I try to find the xpath it act like it does not exist. 

This code below is working to find input fields on the main page of the site. But, if I try the same thing for ones in the popover it will not find it. 😕

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[substring(@id, string-length(@id) - string-length('_3') + 1 ) = '_3']")

    _WD_ElementAction($sSession, $sElement, 'value', "TEST")

Here is the html

popover.thumb.PNG.18dd21fbb559c4038be9ac473796a3d5.PNG

Any idea why it is not finding the element inside these pop overs?

 

 

HTML:

  Reveal hidden contents

 

Edited by SkysLastChance
Add HTML

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Posted

Hi @SkysLastChance,

Please don't post a screenshot of HTML. Either paste the HTML in a code box or attach as an HTML file. Also, it helps if you can provide the URL to a live website. It doesn't have to be for the actual site if that's not possible. 😉

Have you tried locating some of the other elements, such as the table or one of the initial divs?

Dan

Posted (edited)

Sorry, added html

I was able to get this to work using the name element instead of the ID. 

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[substring(@name, string-length(@name) - string-length('_13') + 1 ) = '_13']")

Does not make any sense to me, but it works so I am not going to complain. 

I also figured out clicking buttons on the pop up work just fine as well. 

Edited by SkysLastChance

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

  • Solution
Posted
  Quote

This code below is working to find input fields on the main page of the site. But, if I try the same thing for ones in the popover it will not find it

Expand  

You didn't provide enough details to know if no matching element was found or if the wrong element was found. I suspect that it may have been the later because there's a flaw in your process of checking for the trailing portion of the element's name, id, whatever. Here's proof from the HTML you just posted --

<div id="z8hY_3" class="innerdoc navcomp navroot baselayer covered-layer" style="z-index: 0" data-navcomp-type="layer">
  
<input id="in8hY_3" type="text" spellcheck="false" autocomplete="off" style="box-sizing:border-box;width:100%;vertical-align:top;color:inherit;" name="in8hY_13" class="navitem s_95" data-evt="Fi Fo" data-evh-fi="Pweb.input.inputTextFocusInWrapper" data-evh-fo="Pweb.input.inputTextFocusOutWrapper" data-evt-props="[&quot;altStyle&quot;]" data-befieldchanged-url="./000000000000o3ihg5.mthd" aria-labelledby="y8hY_1l">

Your xpath would return only the Div element, not the Input element. You can replace the "*" in your xpath with the actual element type, but that still won't guarantee that you get the desired element due to the possibility that there are still multiple matches.

 

Posted

I see what you mean.  I will be sure to post the error code going forward. 

This worked.

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[substring(@id, string-length(@id) - string-length('_3') + 1 ) = '_3']")

Thank you!

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Posted

I wonder if something like this would work in your situation --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[substring(@name, string-length(@name) - 2) = '_11']")
$sName = _WD_ElementAction($sSession, $sElement, 'attribute', 'name')
$sPrefix = StringTrimRight($sName, 3)

Obviously needs some error checking. Once you have the correct prefix. you could use it to retrieve the desired element without the need to take a substring of the ID or name each time.

Posted

Oh, That's a good idea. I will be using that. I am now off and running with my script. Thank you again. I appreciate your patients with me. :)

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

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