minkphp / MinkSelenium2Driver

Selenium2 (webdriver) driver for Mink framework
MIT License
509 stars 162 forks source link

document's title has different content ? #193

Open kendoctor opened 9 years ago

kendoctor commented 9 years ago

//Given this element is a title element $element->getText(); // with blank content $element->getHtml(); // it's ok

  1. I put chinese characters in title : 活动首页
  2. I used selenium driver to test it.

Selenium Driver :

    public function getText($xpath)
    {
        $node = $this->findElement($xpath);
        $text = $node->text();
        $text = (string) str_replace(array("\r", "\r\n", "\n"), ' ', $text);

        return $text;
    }

    public function getHtml($xpath)
    {
        return $this->executeJsOnXpath($xpath, 'return {{ELEMENT}}.innerHTML;');
    }

Why these two methods have different implementations for finding element? Why not to convert getHtml() returned result to text ?

aik099 commented 9 years ago

Does example below work?

$page = $session->getPage();
$title = $page->find('css', 'title')->getText();

Why these two methods have different implementations for finding element? Why not to convert getHtml() returned result to text ?

It's because the WebDriver has native method (text()) for retrieving text of an element. We're replacing new line symbols with space to allow content comparison from Behat scenario steps. Unfortunately it doesn't have native method for getting node HTML and that's why we're forced to use JavaScript for that.

kendoctor commented 9 years ago

It does not work.

aik099 commented 9 years ago

But is the <title> tag found? Or it's found but chinese text in it is returned as empty string?

kendoctor commented 9 years ago

yes. Node is found, but with blank text content, html content is ok.

aik099 commented 9 years ago

Then it sounds like bug with Selenium itself, try reporting there.

kendoctor commented 9 years ago

Thanks. If you know, please give me a reference address.

aik099 commented 9 years ago

This seems to be their issue tracker: https://code.google.com/p/selenium/issues/list