Seleniumtest does not work with AJAX Request in a tabview

UI Components for JSF
Post Reply
xor
Posts: 9
Joined: 24 Feb 2014, 12:31

13 Oct 2014, 09:11

Hi,

I don't understand, why my text is not found after an ajax request.
In the first tab, directly after clicking the button, it is found. But not found in the other tab. In the browser I can see the element with my eyes. It is rendered...

Code: Select all

@Test
public void testAjax(@Drone FirefoxDriver browser) {
        browser.get("http://141.28.53.6:8080/SeleniumAjax/");
        
        //click on ajax button
        browser.findElement(By.id("form:tab:button")).click();

        new WebDriverWait(browser, 5).until(ExpectedConditions.visibilityOfElementLocated(By.className("normalOutput")));
        new WebDriverWait(browser, 5).until(ExpectedConditions.visibilityOfElementLocated(By.className("showAfterAjaxClick")));
        
        //switch the tab
        browser.findElement(By.partialLinkText("Godfather Part II")).click();
        
        //here is the crash
        new WebDriverWait(browser, 5).until(ExpectedConditions.visibilityOfElementLocated(By.className("showAfterAjaxClick")));
    }
The error is:

Code: Select all

org.openqa.selenium.TimeoutException: Timed out after 5 seconds waiting for visibility of element located by By.className: showAfterAjaxClick
The testurl is public, you can try it also :-).

I'm using:
- Windows 7
- Firefox 30
- Selenium 2.43.1
- Arquillian Drone 1.3.1.Final

The tabView is rendered with primefaces 5.0.

In this forum I found "$.ajaxPrefilter(function( options ) { options.global = true;});" (http://forum.primefaces.org/viewtopic.p ... um#p110217) but does not work at my situation.

Here is my primefaces/jsf code:

Code: Select all

     <p:outputPanel style="display:block;" id="id_srvc_content">
            <h:form id="form">
                <p:tabView id="tab" orientation="left">
                    <p:tab title="Godfather Part I">
                        <p:commandButton 
                            id="button"
                            value="Ajax Request"
                            action="#{myController.doIt()}"
                            update=":id_srvc_content">
                        </p:commandButton> 
                        <h:outputText 
                            styleClass="normalOutput"
                            value="normal output"/>
                        <br/>
                        <h:outputText 
                            styleClass="showAfterAjaxClick"
                            value="This here can be found after AJAX call" rendered="#{myController.showTextAfterAjax}" />
                    </p:tab>
                    <p:tab title="Godfather Part II">                       
                        <h:outputText 
                            styleClass="showAfterAjaxClick"
                            value="This here can not be found after AJAX call" rendered="#{myController.showTextAfterAjax}" />
                    </p:tab>
                </p:tabView>
            </h:form>
        </p:outputPanel>
The controller:

Code: Select all

@Named
@ViewScoped
public class MyController {

    boolean showTextAfterAjax = false;

    public void doIt() {
        showTextAfterAjax = true;
    }    

    public boolean isShowTextAfterAjax() {
        return showTextAfterAjax;
    }

    public void setShowTextAfterAjax(boolean bla) {
        this.showTextAfterAjax = bla;
    }

}
Using Java EE 7
Primefaces 5.0
JSF 2.2
Glassfish 4.0

xor
Posts: 9
Joined: 24 Feb 2014, 12:31

15 Oct 2014, 10:00

solved it.

Selenium is always looking for the first element in the DOM.

With an exact xpath expression it does work.

Example:
new WebDriverWait(browser, 5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[1]/form/div/div/div[2]/span")));
Using Java EE 7
Primefaces 5.0
JSF 2.2
Glassfish 4.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 64 guests