xpath - Behat/Mink - trouble finding buttons -


my application under test has been developed external suppliers have no control on html structure. application extremely javascript , ajax heavy, numerous dynamically generated buttons , auto-complete lists.

in other words, characteristics of pages filled with:

  • elements no fixed ids (ids generated on fly , have numbers or other text dynamically added them)
  • the same happens classes
  • most of times buttons have no text associated them since either custom coded 'down' arrows lookup lists (which aren't lookup lists hidden divs) or '+' , '-' icons maximise or minimise portions of content. -

it therefore difficult identify these elements, buttons.

i trying write generic 'i click on button near y' type of step not necessary hardcode each , every button (assuming can identify them with) each , every test.

the thinking behind there label of sort close button @ least.

what want to find text label, see if there button inside same scope, , if there not, move 'back' through parent elements, , check if there button inside scope of each parent level, 5 parents.

there might sorts of problems approach curious see if work in general. have run problems.

first tried use xpaths, got xpath of parent through :

$parentelement = $element->getparent();  $parentxpath->getxpath(); 

this give me xpath of : (//html//span[text()='cost center'])[1] , moving through parent elements time, become successively:

(//html//span[text()='cost center'])[1]/..[1]  (//html//span[text()='cost center'])[1]/..[1]/..[1] 

and forth.

the actual button located in: (//html//span[text()='cost center'])[1]/..[1]/..[1]//button has go through parent elements in order there, start (//html//span[text()='cost center'])[1]//button , should end (//html//span[text()='cost center'])[1]/..[1]/..[1]//button should find button.

trying use xpath used:

$button_element = $session->getpage()->find('xpath',$parentxpath."//button") 

i saw 'find' command appends //html front of xpath string xpath tried use ended being (for each parent xpath, using 1 example):

(//html(//html//span[text()='cost center'])[1]/..[1]) 

i stripped out brackets //html, leaving me with:

//span[text()='cost center'][1]/..[1] 

but when tried:

$button_element = $session->getpage()->find('xpath',$strippedparentxpath."//button") 

i got following error:

syntaxerror: failed execute 'evaluate' on 'document': string '(//html//span[text()='cost center'][1]/..[1]//button)[1]' not valid xpath expression 

however, firepath can execute expression , not show syntax error it, although not find actual button (since button located 1 level up, firepath find it).

so question 1 is: wrong xpath can't use in find? looks if //span[text()='cost center'][1]//button not throw same exception, since said, looping through parent xpaths, , starts //span[text()='cost center'][1]//button. crashes on //span[text()='cost center'][1]/..[1]//button.

my second option parent element each time, starting finding text on page, search button inside scope of parent element using findbutton functionality.

looping through parent elements (up maximum of 5):

$parentelement = $parentelement->getparent();  $butonelement = $parentelement->findbutton('xxx'); 

in other words, find button in scope of parent element. problem have how specify generic 'button'.

one has associate text button (depicted 'xxx' above).

but typical example of buttons in application:

<button class="autocomplete_button" type="button" id="button_om_1">&nbsp;</button> 

where class used more once, , id auto-generated , not same number time. there no text associated button since class specifies image.

question 2: how can use 'findbutton' generically find 'button' no specific distinguishing characteristics? please note did try findbutton("button"), taking chance there might 'button' somewhere in button, did not work either. @ least, doesn't work consistently , mean same test randomly seems either find or not find same button when run test couple of times.

i normaly use css selector , that, use navigate class , id's button inside.
easier xpath think, can use

 $this->getsession ()->getpage ()->find ( 'css', '.parrent1 .parrent2 .autocomplete_button ' ); 

i think you know button gonna use in each scenario


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -