Run jquery on selenium/graphene

Posted: January 25, 2013 in web

Page object

...
    protected WebDriver browser = GrapheneContext.getProxy();

    @FindBy(className = "ui-messages-error-summary")
    private List<WebElement> errorMessages;

    public void changeDomain(String url) {
        JavascriptExecutor js = (JavascriptExecutor) browser;
        String jQuerySelector = "$(\".rate-links > li:nth-of-type(4) > a\").attr(\"href\", \"" + url
                + "\" + $(\".rate-links > li:nth-of-type(4) > a\").attr(\"href\"))";
        js.executeScript(jQuerySelector);
    }

Test

    ...	
    @Test
    @OperateOnDeployment(ENROLLMENTS_DEPLOYMENT)
    public void clickLinks_CarDetails_NewPageOpen() {
	...
        carPage.changeDomain("http://car.com");
        Assert.assertTrue("Incorrect page title", carPage.isTitleCorrect("Car Details"));
    }
    ...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s