Fix bug in Selenium when dealing with special characters in link text
This commit is contained in:
parent
aae82b5111
commit
63e1053afa
@ -1,16 +1,26 @@
|
|||||||
var allLabels = inDocument.getElementsByTagName("label");
|
var allLabels = inDocument.getElementsByTagName("label");
|
||||||
|
|
||||||
var candidateLabels = $A(allLabels).select(function(candidateLabel){
|
var candidateLabels = $A(allLabels).select(function(candidateLabel){
|
||||||
var regExp = new RegExp('^' + locator + '\\b', 'i');
|
var regExp = new RegExp('^' + locator + '\\b', 'i');
|
||||||
var labelText = getText(candidateLabel).strip();
|
var labelText = getText(candidateLabel).strip();
|
||||||
return (labelText.search(regExp) >= 0);
|
return (labelText.search(regExp) >= 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (candidateLabels.length == 0) {
|
if (candidateLabels.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
candidateLabels = candidateLabels.sortBy(function(s) { return s.length * -1; }); //reverse length sort
|
|
||||||
|
//reverse length sort
|
||||||
|
candidateLabels = candidateLabels.sortBy(function(s) {
|
||||||
|
return s.length * -1;
|
||||||
|
});
|
||||||
|
|
||||||
var locatedLabel = candidateLabels.first();
|
var locatedLabel = candidateLabels.first();
|
||||||
var labelFor = locatedLabel.getAttribute('for');
|
var labelFor = locatedLabel.getAttribute('for');
|
||||||
|
|
||||||
if ((labelFor == null) && (locatedLabel.hasChildNodes())) {
|
if ((labelFor == null) && (locatedLabel.hasChildNodes())) {
|
||||||
return locatedLabel.firstChild; //TODO: should find the first form field, not just any node
|
// TODO: should find the first form field, not just any node
|
||||||
|
return locatedLabel.firstChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
return selenium.browserbot.locationStrategies['id'].call(this, labelFor, inDocument, inWindow);
|
return selenium.browserbot.locationStrategies['id'].call(this, labelFor, inDocument, inWindow);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
var locationStrategies = selenium.browserbot.locationStrategies;
|
var locationStrategies = selenium.browserbot.locationStrategies;
|
||||||
|
|
||||||
return locationStrategies['id'].call(this, locator, inDocument, inWindow)
|
return locationStrategies['id'].call(this, locator, inDocument, inWindow)
|
||||||
|| locationStrategies['name'].call(this, locator, inDocument, inWindow)
|
|| locationStrategies['name'].call(this, locator, inDocument, inWindow)
|
||||||
|| locationStrategies['label'].call(this, locator, inDocument, inWindow)
|
|| locationStrategies['label'].call(this, locator, inDocument, inWindow)
|
||||||
|
@ -79,7 +79,12 @@ module Webrat
|
|||||||
webrat_deprecate :clicks_button, :click_button
|
webrat_deprecate :clicks_button, :click_button
|
||||||
|
|
||||||
def click_link(link_text_or_regexp, options = {})
|
def click_link(link_text_or_regexp, options = {})
|
||||||
pattern = adjust_if_regexp(link_text_or_regexp)
|
if link_text_or_regexp.is_a?(Regexp)
|
||||||
|
pattern = "evalregex:#{link_text_or_regexp.inspect}"
|
||||||
|
else
|
||||||
|
pattern = link_text_or_regexp.to_s
|
||||||
|
end
|
||||||
|
|
||||||
locator = "webratlink=#{pattern}"
|
locator = "webratlink=#{pattern}"
|
||||||
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
||||||
selenium.click locator
|
selenium.click locator
|
||||||
|
Loading…
Reference in New Issue
Block a user