-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More methods for NodeElement children manipulations #586
base: master
Are you sure you want to change the base?
Changes from all commits
cc1ce2e
96f97b1
4d7d991
c499b97
0f20bfe
d832fd6
ef96fdb
ca4a9e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,86 @@ public function getParent() | |
return $this->find('xpath', '..'); | ||
} | ||
|
||
/** | ||
* Returns All child elements (including descendant) to the current one. | ||
* | ||
* @return static[]|null | ||
*/ | ||
public function getAllChildren() | ||
{ | ||
return $this->findAll('xpath', 'descendant::*'); | ||
} | ||
|
||
/** | ||
* Returns All direct child elements (NOT including deeper descendant) to the current one. | ||
* | ||
* @return static[]|null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
*/ | ||
public function getDirectChildren() | ||
{ | ||
return $this->findAll('xpath', 'child::*'); | ||
} | ||
|
||
/** | ||
* Returns the first child element to the current one. | ||
* | ||
* @return static|null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
*/ | ||
public function getFirstChild() | ||
{ | ||
return $this->find('xpath', 'child::*[1]'); | ||
} | ||
|
||
/** | ||
* Returns the last direct child element to the current one. | ||
* | ||
* @return static|null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
*/ | ||
public function getLastChild() | ||
{ | ||
return $this->find('xpath', 'child::*[last()]'); | ||
} | ||
|
||
/** | ||
* Returns all preceding sibling elements to the current one. | ||
* | ||
* @return static[]|null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
*/ | ||
public function getPreviousSiblings() | ||
{ | ||
return $this->findAll('xpath', 'preceding-sibling::*'); | ||
} | ||
|
||
/** | ||
* Returns the preceding sibling element close to the current one. | ||
* | ||
* @return static|null | ||
*/ | ||
public function getPreviousSibling() | ||
{ | ||
return $this->find('xpath', 'preceding-sibling::*[1]'); | ||
} | ||
|
||
/** | ||
* Returns all following sibling elements to the current one. | ||
* | ||
* @return static[]|null | ||
*/ | ||
public function getNextSiblings() | ||
{ | ||
return $this->findAll('xpath', 'following-sibling::*'); | ||
} | ||
|
||
/** | ||
* Returns the following sibling element close to the current one. | ||
* | ||
* @return static|null | ||
*/ | ||
public function getNextSibling() | ||
{ | ||
return $this->find('xpath', 'following-sibling::*[1]'); | ||
} | ||
|
||
/** | ||
* Returns current node tag name. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,29 @@ public function findById($id) | |
return $this->find('named', array('id', $id)); | ||
} | ||
|
||
/** | ||
* Finds element by its name. | ||
* | ||
* @param string name element name | ||
* @return static|null | ||
*/ | ||
public function findByName($name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this method much. The name is not a unique identifier at all, so I'm not sure returning a single element makes sense |
||
{ | ||
$name = $this->getSelectorsHandler()->xpathLiteral($name); | ||
return $this->find('named', array('name', $name)); | ||
} | ||
|
||
/** | ||
* Finds elements by its tag. | ||
* | ||
* @param string tag element tag | ||
* @return static[]|null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong. It always returns a list of NodeElement, even when being called on a DocumentElement instance. It should be |
||
*/ | ||
public function findByTag($tag) | ||
{ | ||
return $this->findAll('css', $tag); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation is wrong. This is not finding by tag only |
||
} | ||
|
||
/** | ||
* Checks whether element has a link with specified locator. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findAll
can never returnnull
.and it should be
NodeElement[]
orself[]
, notstatic[]
. If you extend the NodeElement class, the elements returned here will not use the child class (findAll()
always returns a list of NodeElement instances)