Selenium framework and Chrome browser incompatibility issues

Source: Internet
Author: User

In an accidental case, on chrome with the selenium framework to crawl a page element with ID xx, using Webdriver's Findelement (). Click () method to hit, originally in the Firefox browser run a good program error. compiler to the newspaper InvocationTargetException, a bit of experience coder know, this anomaly range is too wide, And the most painful thing is not to give any exception information (stacktraceinformation is null) This time we have to use the Getcause method to get the real exception that caused it, and get abnormal information, so that we can track the location. This is not the focus of this article, it is not here to say the specific method.

Previously found manual click Normal, and using the Isdisplyed and Isexists method to determine that it is not obscured by other elements or not in time to load out, so you can eliminate the waiting period and the possibility of being obscured by other elements;

? Viewing the XPath discovery of an element is not nested by any frame or IFRAME, so you can also exclude the possibility that the focus does not switch to the current element being clicked.

In Firefox and IE can be normal crawl, and the normal simulation click, and then combined with the View page HTML and JS code, the page code has the possibility of a bug can also be ruled out.

After the final positioning tracking to Google browser driver Chromedriver, remember that selenium is an open source project, so to GitHub search this framework. Find the driver part, sure enough, Firefox driver or selenium personnel development, and Google's driver is Google's internal staff developed. After all, it is not the original class out of things, compatibility is not good, some things do not support is normal, even Google's engineers can not be perfect.

Now that we've found out why, they're not compatible. I don't need that method on chrome. Invoking JS's Click event directly

Webdriver Driver = new Chromedriver ();

Javascriptexecutor JSE = (javascriptexecutor) driver;?

    • webelement element = Driver.findelement (By.id ("XX"));
    • Jse.executescript ("Arguments[0].click ();", Element);
    • ?

Get.?

Selenium framework and Chrome browser incompatibility issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.