merlinthemagic / MTS

Automation Tools for PHP
GNU Lesser General Public License v3.0
111 stars 29 forks source link

Can not click Element by ClassName or linkText as same Facebook Driver #4

Closed quyeticb closed 8 years ago

quyeticb commented 8 years ago

hello, I want click by classname (many classname duplicate). How to click with classname $n ex:

<a class="one" href="#">One</a>
<a class="one" href="#">Two</a>
......

I Want click link Two

And How do run PhantomJS via Sock 5 proxy?

quyeticb commented 8 years ago

OK, I solved run PhantomJS via socks 5. But Not solve the first problem. Need support!

merlinthemagic commented 8 years ago

Hi,

I would select the set of links in class "one" (a.one), then a sub selection using "nth-of-type(n)" like this:

$selector = "a.one:nth-of-type(2)";

You could use getElement() and make sure you have the right link. I also saw you wanted to click the link using mouseEventOnElement() before you edited the issue. In the Readme you will see that mouseEventOnElement() can only click elements that cover an area on the page. A vanilla hyperlink is just a link of text, to click use the clickElement() method instead.

quyeticb commented 8 years ago

Thanks for fast support. I will check it again. Now, I have a problem with the function sendKeyPresses If string to send is utf-8 is always error (timeout error). You can check and review it.

And If error, these folder in WorkDirectory do not delete, may be error for next PhantomJS instances

merlinthemagic commented 8 years ago

What's your OS, version and architecture?

Can you send me the string that fails? The fact that the process does not exit is quite odd. There is only two scenarios I can think of that would cause the process to live beyond the lifetime of the PHP script. That would be if the command you execute is the very first one OR if you are using a very old version of MTS. When did you download MTS and are you using master or a specific release?

quyeticb commented 8 years ago

Oh, one moment, I create many instances while do not terminate it before. But $windowObj->close() still not working. This is error:

PHP Fatal error: Uncaught Exception: MTS\Common\Devices\Browsers\PhantomJS::browserCloseWindow>> Got result code: 0, EMsg: Failed to close window. Error: ReferenceError: Can't find variable: myArray, ECode: 0 in /MTS/Common/Devices/Browsers/PhantomJS.php:111 Stack trace:

0 /MTS/Common/Devices/Browsers/Base.php(86): MTS\Common\Devices\Browsers\PhantomJS->browserCloseWindow(Object(MTS\Common\Devices\Browsers\Window))

1 /MTS/Common/Devices/Browsers/Window.php(79): MTS\Common\Devices\Browsers\Base->closeWindow(Object(MTS\Common\Devices\Browsers\Window))

2 /test.php(185): MTS\Common\Devices\Browsers\Window->close()

3 {main}

thrown in /MTS/Common/Devices/Browsers/PhantomJS.php on line 111

merlinthemagic commented 8 years ago

Are you using the current version of master? If not how old is it?

Since you customized MTS do you have a repository where I can look at the code?

I am puzzled because $windowObj->close() does not invoke terminate of the entire browserObj just that window.

quyeticb commented 8 years ago

I'm using latest MTS release.

merlinthemagic commented 8 years ago

The reason I would like to see the code is that the Exception trace shows:

Can't find variable: myArray, ECode: 0 in /MTS/Common/Devices/Browsers/PhantomJS.php:111

That variable is not defined in the stock MTS package. It's hard to help you without knowing how you customized the package.

quyeticb commented 8 years ago

Thank you, I will track it again, but I do not modifie PhantomJS.php. PS: I Like your source code. It is useful, instead of having to use webdriver. You can review the sendKeyPresses with an unicode string. Ex: sendKeyPresses('Côte dIvoire')

merlinthemagic commented 8 years ago

The exception is relayed from the .js executed by phantomJS. It's not a PHP exception originally.

quyeticb commented 8 years ago

Yes, I fixed it! Thanks!