SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.7k stars 8.19k forks source link

By.LinkText() doesn't work in Edge for button with span inside #1622

Closed Omorocker closed 8 years ago

Omorocker commented 8 years ago

I have this HTML:

<button type="button" class="greenButton_arrow">
  <span>
    <span>zur Kasse</span>
  </span>
</button>

If I do

IWebElement.FindElement(By.LinkText("zur Kasse"));

then nothing is found in Edge. In Chrome, Firefox, MSIE and Opera, this works fine.

If I do

string text = IWebElement.FindElement(By.XPath("//button[@type='button'][.//span[text()='zur Kasse']]")).Text;

then I get: "\r\nzur Kasse"

lukeis commented 8 years ago

First, edge driver issues should be logged with Microsoft: http://connect.microsoft.com/

Second, I do not believe your assertion that finding by LinkText works in Chrome / Firefox (it shouldn't there either, LinkText only scans "<a>" tags. I just tried that in python and the element was not found in both:

>>> from selenium import webdriver as w
>>> d = w.Chrome()
>>> d.get('about:blank')
>>> d.execute_script('document.body.innerHTML = arguments[0];', """<button type="button" class="greenButton_arrow">
...   <span>
...     <span>zur Kasse</span>
...   </span>
... </button>""")
>>> d.find_element_by_link_text('zur Kasse')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 282, in find_element_by_link_text
    return self.find_element(by=By.LINK_TEXT, value=link_text)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"zur Kasse"}
  (Session info: chrome=48.0.2564.103)
  (Driver info: chromedriver=2.19.346063 (38b35413bd4a486d436a9749e090454bc9ff6708),platform=Mac OS X 10.10.5 x86_64)

>>> d.quit()
>>> d = w.Firefox()
>>> d.get('about:blank')
>>> d.execute_script('document.body.innerHTML = arguments[0];', """<button type="button" class="greenButton_arrow">
...   <span>
...     <span>zur Kasse</span>
...   </span>
... </button>""")
>>> d.find_element_by_link_text('zur Kasse')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 282, in find_element_by_link_text
    return self.find_element(by=By.LINK_TEXT, value=link_text)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"link text","selector":"zur Kasse"}
Omorocker commented 8 years ago

Hi Luke,

thanks for trying to reproduce! But I don’t think it is a matter of belief whether LinkText works in Chrome / Firefox or not. I am using the exact same test case and the same locators for all browsers, also for Safari and PhantomJS, on Win7, Win10, MacOS and Android. The test case is green for all of them, except for Edge.

You can try it yourself. Simplified example s. below.

So before I post this on http://connect.microsoft.com/ , are you still sure this is an Edge issue, not a Selenium issue? I don’t know the internal architechture and thus cannot judge this.

Bye… Kimmy

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;

namespace ConsoleApplication1
{
    static class Program
    {
        static void Main()
        {
            var driver = new ChromeDriver();
            //var driver = new EdgeDriver();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
            driver.Navigate().GoToUrl("http://www.cornelsen.de/");
            driver.FindElement(By.Id("ecp-search")).SendKeys("9783060204991" + Keys.Enter);
            driver.FindElement(By.CssSelector("div.button_warenkorb_im_kontext>a")).Click();
            driver.SwitchTo().Frame(1);
            IWebElement element;
            try
            {
                element = driver.FindElement(By.LinkText("zur Kasse")); // found in all browsers aside from Edge
            }
            catch (Exception)
            {
                element = driver.FindElement(By.XPath("//button[@type='button'][.//span[text()='zur Kasse']]")); // found in all browsers
            }
            string text = element.Text; // returns "\r\nzur Kasse" in Edge, "zur Kasse" in all other browsers
        }
    }
}
nikolmarku commented 7 years ago

select by linktext still does not work Release 14393 Version: 3.14393 | Edge version supported: 14.14393

tjnhdo commented 7 years ago

I execute xpath like //span[contains(@Class,'pfandobjekt')]. This work on IE Firefox and Chrome browser. But with Edge, I can't Microsoft Edge 38.14393.1066.0 Microsoft EdgeHTML 14.14393 Selenium 3.4.0

Please help me check.