SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
347 stars 195 forks source link

ChromeDriver is returning short URLs for HREF where it should be the full length #1824

Closed lukeis closed 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 1824

When I have a page with a link, Firefox is changing this link. Example, suppose I am
at http://www.google.com and exists the following link:

<a href="/foo" id="foo_link">Bar</a>

I can write this code:

# ... instantiate the browser here
element = browser.find_element_by_id('foo_link')
print element.get_attribute('href') # should be "/foo"

The result on Firefox webdriver will be "http://www.google.com/foo", but it should
be only "/foo". On Chrome webdriver, everything works fine :)

Reported by franciscossouza on 2011-06-12 23:13:33

lukeis commented 8 years ago
This is correct behaviour by the Firefox Driver and incorrect behaviour by the ChromeDriver.

Reported by theautomatedtester on 2011-06-13 10:30:15

lukeis commented 8 years ago
HtmlUnitDriver used to return short URLs too.
An attached patch fixes this problem (and includes new tests for "a with href" and
"img with src").

Reported by barancev on 2011-06-13 12:20:06


lukeis commented 8 years ago
I don't think this is the right behaviour.

If I put href="/foo", then the "href" attribute of element a is "/foo", not "http://blablabla/foo"!

Reported by franciscossouza on 2011-06-13 12:22:49

lukeis commented 8 years ago
@franciscossouza: Not all browsers have the ability to return the relative URL, so we've
decided to fetch the href property/IDL attribute, which is always absolute, to get
consistent behaviour.

See e.g. issue 1634.

Reported by jari.bakken on 2011-06-13 12:56:41

lukeis commented 8 years ago
Huum, I see :)

So, great job! \o/

Reported by franciscossouza on 2011-06-13 13:10:10

lukeis commented 8 years ago
@jari.bakken: The problem appears to be IE (as always).

http://msdn.microsoft.com/en-us/library/ms536429(v=vs.85).aspx

By default, element.getAttribute(attributeName) "performs a property search that is
not case-sensitive, and returns an interpolated value if the property is found."  This
is why we always get the absolute URL for src and href attributes.  According to the
above documentation, if we use element.getAttribute("href", 2), we should get the attribute
value as a string.

I agree with @franciscossouza that if I put href="/foo", I should be able to get back
"/foo" when using WebElement.getAttribute (an actual attribute lookup), but we seem
to have standardized on WebElement.getAttribute always getting the property instead
of the attribute for href and src because of our incorrect usage of the API.

I would argue, again, that only having a WebElement.getAttribute and not a WebElement.getProperty
method creates a confusing API with difficult to explain behavior and lots of special
edge cases like this.  It has been argued that users don't know the difference between
an attribute and a property.  If that is the case, we should educate them and fix our
API.

Reported by jmleyba on 2011-06-14 14:50:00

lukeis commented 8 years ago
The confusion between properties and attributes is widespread and common. The current
API supports the common-case, where a user doesn't care about the difference. If a
user _does_ care about the difference, there's a very easy way to go about finding
this out using the JavascriptExecutor.

Reported by simonstewart@google.com on 2011-06-14 15:00:27

lukeis commented 8 years ago
There is another edge case: href="" (empty string) - the behavior differs in browsers,
not in drivers.

For example, if we have a page http://site.com/page.html with such an empty link:
- IE considers it to be a link to the directory http://site.com/
- all the other browsers (FF, Opera, Chrome) think it is a link to the same page http://site.com/page.html

Reported by barancev on 2011-06-14 16:01:45

lukeis commented 8 years ago
According to README.chromium[1], the ChromeDriver is currently using the atoms built
from r12331.  The ChromeDriver atoms are generated using //javascript/chrome-driver:atoms,
which is using //javascript/webdriver-atoms:get_attribute, which in turn has the desired
behavior as of r12176.

Closing this bug. There is no action to take.

[1] http://src.chromium.org/svn/trunk/src/third_party/webdriver/README.chromium
[2] http://code.google.com/p/selenium/source/browse/trunk/javascript/chrome-driver/build.desc#21

Reported by jmleyba on 2011-06-14 16:16:55

lukeis commented 8 years ago
The name of "getAttribute" is confusing, it is expected to return attribute, not property
!!!
Please add a getProperty method to the WebDriver.

Reported by dieudonc on 2012-06-20 10:07:58

lukeis commented 8 years ago
I don't agree with coment #7 nor #9. The consistency between browser is not expected
to break the method semantic. Whatever javadoc says, method name can't be unrelated
to what a method does. If a method is called "jump" ans the javadoc says "dive", you
have a bug. And if some people started to expect "jump" behaviour and other "dive",
the former is OK.
Javadoc is here to clarify usage and meaning of a method, not to counter it and change
the common sense of words !!!

Please add a getProperty method as suggested in comment #10.

Reported by joachim.e.rousseau on 2012-06-20 10:21:24

lukeis commented 8 years ago
We've found a lot of our users don't recognize when to ask for a property or an attribute,
so the two are accessible through a single method - getAttribute.  If you know exactly
which value you want, you can always access it through JS:

((JavascriptExecutor) driver).executeScript("return arguments[0][arguments[1]]", webElement,
propertyName);

You can always mail selenium-developers@googlegroups.com if you want to start a discussion
about the merits of a getProperty method.

Reported by jmleyba on 2012-06-21 13:04:43

lukeis commented 8 years ago
So now, ignorance has become a point of view. Tell it to Dilbert.
No, both property and attribute are not accessible to a single method : getAttribute
is accessing property only. And that is the problem. Because some users (that a clear
javadoc and one could educate, plus one or two clarifications for newbies lost on bugtracker)
ignore the difference between a property and an attribute, they don't understand why
their tests are failing : "href" attribute and property on A element haven't the same
value !
It's a pity you listen at ignorant whiners while you penalize developers that are you
best help to track bugs. That won't improve the power Selenium nor the knowledge of
beginners.

Reported by joachim.e.rousseau on 2012-06-21 13:20:43

lukeis commented 8 years ago
You welcome to the mailing list where the audience is much wider.
Nobody reads closed issues in the tracker :)

Reported by barancev on 2012-06-21 13:28:28

lukeis commented 8 years ago
I'll add that you made 2 mistakes :
1) when there was an inconsistency between browser, with some returning property and
others returning attribute, you unexpectedly got the get_Attribute_ method returning
the _property_ on every webdriver.
2) if users are condused with attribute/property, you have the choice. As they're confused,
there no reason to chose one over the other. Except your method name is get... _Attribute_
!

Reported by joachim.e.rousseau on 2012-06-21 13:31:47

lukeis commented 8 years ago
I wasn't criticizing you or any other users, I was simply stating the reason for there
being a single getAttribute method.  This was a decision made as a group - not a single
developer.

If you have an issue with it, please mail the aforementioned list.  You can also hop
on IRC (#selenium on freenode).  Most of the core developers are on throughout the
day.

Reported by jmleyba on 2012-06-23 16:25:15

lukeis commented 8 years ago
I'm not a single developer. We are more than 100 devs at my company expecting getAttribute
to return the short URL we set in the html A tag. 
That's why Selnium is missing a getProperty (that would return the full URL as it is
expected for the href dom property)

Reported by joachim.e.rousseau on 2012-06-24 15:09:13

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 18:13:02