Hi Krishantha,

Thanks for looking in to it. Will go with the JavaScriptExecutor method
then.

Thanks,
Supun

On Mon, Dec 15, 2014 at 4:35 PM, Krishantha Samaraweera <[email protected]
> wrote:
>
> Hi Supun,
>
> I tried out several alternative options to automate your scenario without
> enabling input filed visibility, but non of them works.
>
> So our recommendation is to go with JavaScriptExecutor. If something
> cannot be directly automated, you need to inject testability into your
> code, thus altering the application behaviour at run time to provide
> automate friendly UI is okay. You can use following code snippet as a
> reference.
>
>         WebDriver driver = new FirefoxDriver();
>         driver.get("http://localhost:9763/mlUI/";); //don't hard code the
> URL
>
> driver.findElement(By.xpath("//input[@name='username']")).sendKeys("admin");
>
> driver.findElement(By.xpath("//input[@name='password']")).sendKeys("admin");
>
>
> driver.findElement(By.xpath("//input[@class='blueButton']")).click();
>
> driver.findElement(By.xpath("//img[@id='new_project_img']")).click();
>
>
> driver.findElement(By.xpath("//input[@id='projectName']")).sendKeys("testProject");
>
> driver.findElement(By.xpath("//textarea[@id='projectDescription']")).sendKeys("testDesc");
>
> driver.findElement(By.xpath("//input[@id='workflowName']")).sendKeys("workflow");
>
>         JavascriptExecutor js = (JavascriptExecutor) driver;
>
> js.executeScript("document.getElementById(\"datasetName\").disabled =
> false;");
>
> driver.findElement(By.xpath("//input[@id='datasetName']")).sendKeys("/Users/krishantha/Desktop/train.csv");
>
> Thanks,
> Krishantha.
>
>
>
> On Mon, Dec 15, 2014 at 10:17 AM, Supun Sethunga <[email protected]> wrote:
>>
>> Hi Awanthika,
>>
>> Thanks for the link. But in my case, the hidden field is a <input
>> type=file> element, of which i want to change the 'value' (set the file
>> path). This is not possible through JavaScript for security reasons [1] ,
>> [2]. Workaround is to change the 'visibility' through javaScript which is
>> possible, and then trigger it using selenium. But this again brings the
>> concern on changing the application by a test case, which Saneth has
>> mentioned above.
>>
>> [1]
>> http://stackoverflow.com/questions/20537696/remember-and-repopulate-file-input/20537822#20537822
>> [2]
>> http://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html
>>
>> Thanks,
>> Supun
>>
>> On Mon, Dec 15, 2014 at 8:39 AM, Awanthika Senarath <[email protected]>
>> wrote:
>>>
>>> Hi Supun,
>>>
>>> This post [1] discusses few suggestions on triggering hidden div
>>> elements.
>>>
>>> [1]
>>> http://stackoverflow.com/questions/12040615/selenium-webdriver-clicking-on-hidden-element
>>>
>>> thanks and regards
>>>
>>> On Mon, Dec 15, 2014 at 7:35 AM, Supun Sethunga <[email protected]> wrote:
>>>
>>>> Hi Krishantha,
>>>>
>>>> Test cases hasn't been pushed to any remote repo yet. Will share the
>>>> local copy of the pack, which includes the test cases, with you.
>>>>
>>>> Regards,
>>>> Supun
>>>>
>>>> On Sat, Dec 13, 2014 at 10:28 AM, Krishantha Samaraweera <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi Supun,
>>>>>
>>>>> Can you share a pack to reproduce this behaviour. Please mention the
>>>>> steps to follow.
>>>>>
>>>>> Thanks,
>>>>> Krishantha.
>>>>>
>>>>>
>>>>>
>>>>> On Sat, Dec 13, 2014 at 8:33 AM, Supun Sethunga <[email protected]>
>>>>> wrote:
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I am writing a test case for a CSV-file uploading function, of a
>>>>>> Jaggery page. There is a browse button which allows to browse any file in
>>>>>> the file system. Once a file is selected and clicked the 'import' button,
>>>>>> file get uploads. Underneath what happens is, once the file is browsed 
>>>>>> and
>>>>>> selected, it gets assigned to a "*<input type
>>>>>> ='file' name='dataFile'>* " element. Follow is the html code.
>>>>>>
>>>>>>                     *<div id="dataSource" class="row">*
>>>>>> *                        <div class="cell" > Data Source:</div>*
>>>>>> *                        <div class="cell">*
>>>>>> *                            <input type="text" id="datasetName"
>>>>>> name="datasetName" disabled/>*
>>>>>> *                            <input type="button" id="datasetOpen"
>>>>>> value="Browse" /> *
>>>>>> *                            <span id="datasetNameValidator"></span>*
>>>>>> *                        </div>*
>>>>>> *                        <input type="file" size="60" name="dataFile"
>>>>>> id="**dataFile**"> *
>>>>>> *                    </div>*
>>>>>> *                    <div id="import" class="row">*
>>>>>> *                        <div class="cell"><input type="submit"
>>>>>> value="Import"></div> *
>>>>>> *                    </div>*
>>>>>>
>>>>>> I've not been able trigger this using Selenium driver, since once the
>>>>>> 'browse' button is clicked, the popup opens is a OS level window, thus
>>>>>> selenium driver cannot handle it. As a workaround, tried setting the file
>>>>>> path to the *<input type ='file' name='dataFile'> *html element,
>>>>>> rather than browsing the file. But again, Selenium driver is unable to 
>>>>>> set
>>>>>> the path to this element as it is an 'hidden' element.
>>>>>> (As the offline discussion, if I change the visibility of this file
>>>>>> element to 'visible', then the Selenium driver can set the file path to 
>>>>>> the
>>>>>> element, and the import function get triggered correctly.)
>>>>>>
>>>>>> Any idea on how to trigger such a file uploading with Selenium, or
>>>>>> any workaround?
>>>>>>
>>>>>> Much appreciate any help, as this has become a blocker for writing
>>>>>> the rest of the test cases.
>>>>>>
>>>>>> Thanks
>>>>>> Supun
>>>>>>
>>>>>> --
>>>>>> *Supun Sethunga*
>>>>>> Software Engineer
>>>>>> WSO2, Inc.
>>>>>> lean | enterprise | middleware
>>>>>> Mobile : +94 716546324
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Krishantha Samaraweera
>>>>> Senior Technical Lead - Test Automation
>>>>> Mobile: +94 77 7759918
>>>>> WSO2, Inc.; http://wso2.com/
>>>>> lean . enterprise . middlewear.
>>>>>
>>>>
>>>>
>>>> --
>>>> *Supun Sethunga*
>>>> Software Engineer
>>>> WSO2, Inc.
>>>> lean | enterprise | middleware
>>>> Mobile : +94 716546324
>>>>
>>>> _______________________________________________
>>>> Dev mailing list
>>>> [email protected]
>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>
>>>>
>>>
>>> --
>>> Awanthika Senarath
>>> Software Engineer, WSO2 Inc.
>>> Mobile: +94717681791
>>>
>>>
>>>
>>
>> --
>> *Supun Sethunga*
>> Software Engineer
>> WSO2, Inc.
>> lean | enterprise | middleware
>> Mobile : +94 716546324
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
> --
> Krishantha Samaraweera
> Senior Technical Lead - Test Automation
> Mobile: +94 77 7759918
> WSO2, Inc.; http://wso2.com/
> lean . enterprise . middlewear.
>


-- 
*Supun Sethunga*
Software Engineer
WSO2, Inc.
lean | enterprise | middleware
Mobile : +94 716546324
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to