selene icon indicating copy to clipboard operation
selene copied to clipboard

handle different rendering of 'href' attribute that comes from Selenium Webdriver

Open yashaka opened this issue 5 years ago • 2 comments

Same issue for Selenide from java

GIVEN

element = browser.all('#filters li a')[1]
webelement = element()

THEN

webelement.get_attribute('outerHTML')
# => '<a href="#/active">Active</a>'

AND

webelement.get_attribute('href')
# => 'https://todomvc4tasj.herokuapp.com/#/active'

have different results for 'href' attribute

Actually in browser inspector, we see href in DOM as #/active, and in browser console the js code will return #/active, but if in browser inspector we hover mouse on the href attribute of element it will display hint with the "absolute rendering of the link". Seems like Selenium Webdriver simulates such "browser style rendering" for href... But then it becomes inconsistent with how Selenium Webdriver renders 'outerHTML' attribute...

Open Points:

  • how to handle this in Selene?
    • add option to config.get_attribute_by_js to be able to switch from webdriver to js rendering of all attributes?
  • should it be improved on Selenium Webdriver side?
    • options:
      • make 'href' return relative url as in HTML?
      • improve 'outerHtml' return absoluter URL too?

Why care?

Because the following code will fail:

element.should(have.attribute('href').value('#/active'))

And the user will be confused with such behaviour...

Especially that error message will how that element has href attribute as expected...

yashaka avatar Apr 18 '20 10:04 yashaka

I had the same problem and always made workaround like

base_url = 'http://my.domain/'
element.should(have.attribute('href').value(base_url + '#/active'))

But what about to make a little extension of selene api, making difference between like this:

element.should(have.attribute('href').value('#/active'))
element.should(have.attribute('href').exact_value(base_url + '#/active'))

Or like this:

element.should(have.attribute('href').value(base_url + '#/active'))
element.should(have.attribute('href').value(contains('#/active')))

aleksandr-kotlyar avatar Apr 18 '20 22:04 aleksandr-kotlyar

We already have condition have.value_containing

"attribute have value" I English means "exact" by default.

So, here we just need to fix attribute.value to work as expected.

Selenium can be different and low level. But in Selene we match users not machines in the API;)

Yet the fix will not be obvious and we might want to add some option to config.... Like browser.config.get_attribute_by_js, turned on by default... Or maybe not... Need to think about it)

On Sun, Apr 19, 2020, 01:08 Aleksandr Kotlyar [email protected] wrote:

I had the same problem and always made workaround like

base_url = 'http://my.domain/' element.should(have.attribute('href').value(base_url + '#/active'))

But what about to make a little extension of selene api, making difference between like this:

element.should(have.attribute('href').value('#/active'))

element.should(have.attribute('href').exact_value(base_url + '#/active'))

Or like this:

element.should(have.attribute('href').value(base_url + '#/active'))

element.should(have.attribute('href').value(contains('#/active')))

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/yashaka/selene/issues/211#issuecomment-615960099, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO6ZHTWANHFNTWGPSKEQO3RNIQHHANCNFSM4MLJWJDQ .

yashaka avatar Apr 19 '20 06:04 yashaka