@Override
public void set( ElementDescriptor descriptor ) {
String fileName = determineFile( descriptor.getValue() );
ElementStub fileStub = find( descriptor );
if ( !fileStub.exists() ) {
fail( "Could not find file input: " + descriptor );
}
if ( StringUtils.equalsIgnoreCase( descriptor.getType(), TYPE_FILE ) ) {
// Do a simple set
LOG.debug( "Performing a simple file set on " + descriptor );
fileStub.setFile( fileName );
}
else {
// Try setting with javascript and changing the element type
// This might work in situations where the javascript requires the form to not be empty
LOG.debug( "Performing a javascript change type file set on " + descriptor );
browser.setFile( fileStub, fileName );
// If it is still a file type, we should change it
if ( !StringUtils.contains( fileStub.toString(), "textbox" ) ) {
if ( browser.isIE() ) {
browser.execute(
fileStub + ".outerHTML = " + fileStub + ".outerHTML.replace(/type=['\"]?file['\"]?/, \"type=text\")" );
}
else {
browser.execute( fileStub + ".type = \"text\";" );
}
addParents( browser.textbox( descriptor.getSahiArguments() ), descriptor ).setValue( fileName );
}
else {
fileStub.setValue( fileName );
}
}
}