2 Replies - 944 Views - Last Post: 10 June 2011 - 02:59 AM

#1 CheckersW   User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 198
  • Joined: 04-April 09

Question about XPath "contains()" function

Posted 09 June 2011 - 06:08 PM

Hey guys,

First of all let me apologise if I've posted this in the wrong forum; I wasn't sure where it really fits.

I'm writing a script for selenium to do some tests on my website, and I've run into a problem with a few trick comboboxes. The problem is that the names of the comboboxes aren't hardcoded - they're based on an object's GUID, so the name is always memberPosition_<guid>. Fortunately, there will only be one option to select in my tests (The combobox default value is "none" and the other one is the one I want).

At the moment I've tried to use the XPath "contains()" function to choose the memberPosition, but selenium can't find the element (I'm obviously not providing the right name). My current code for this bit is:
		$this->selenium->click("//*[contains(name(), 'memberPosition')]");
		$this->selenium->select("//*[contains(name(), 'memberPosition')]", "label=$firstPositionName");



Any idea what I'm doing wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Question about XPath "contains()" function

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: Question about XPath "contains()" function

Posted 09 June 2011 - 10:27 PM

name() refers to the name of the element (because that’s what you’re processing). try //*[contains(@name, 'memberPosition')]. remember that special attributes in HTML like name or id are regular attributes in XML.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Question about XPath "contains()" function

Posted 10 June 2011 - 02:59 AM

XPath is sort of an odd duck, so we'll move this to the more generic Web Development forum.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1