handle different rendering of 'href' attribute that comes from Selenium Webdriver
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?
- options:
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...
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')))
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 .