F
F
Franco Mannino2017-01-07 20:33:22
selenium
Franco Mannino, 2017-01-07 20:33:22

How to search for selectors in PhantomJS?

Experimenting with Selenium.
For example, if you create an object
ChromeDriver chrom = new ChromeDriver();
, everything works, but the same variant with PhantomJS does not work (below) - it throws an exception. What to do here?

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.PhantomJS;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;

namespace UnitTestProject1
{
    /// <summary>
    /// Summary description for UnitTest2
    /// </summary>
    [TestClass]
    public class UnitTest3
    {
        PhantomJSDriver phantomjs;

        [TestMethod]
        public void TestMethod3()
        {
            phantomjs = new PhantomJSDriver();
            phantomjs.Navigate().GoToUrl("http://www.google.com/");
            phantomjs.FindElement(By.Id("lst-ib")).SendKeys("AutoQA.org");
            phantomjs.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
            Screenshot screenshot = ((ITakesScreenshot)this.phantomjs).GetScreenshot();
            screenshot.SaveAsFile(@"C:\Users\User\Desktop\Новая папка\image_" + (DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")).ToString() + ".jpg", ImageFormat.Jpeg);

        }

        // разрушение объекта драйвера после окончание теста.
        [TestCleanup]
        public void TearDown()
        {
            phantomjs.Quit();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Franco Mannino, 2017-01-08
@garinov

For some reason, Google renders differently in different browsers. In this case, the phantom gets
class="lst tiah"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question