Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

Failed to use command "getElementAttribute" in webDrvier.

$
0
0

Hi Microsoft guys,

I have written a practice to learn IEDC webDriver (based on the webdriver C# demo)

Everything worked ok but failed during using 'getElementAttribute'

WorkFlow:

1. open "http://www.bing.com" - passed

2. find element for "input[name='go']" - passed.

3. find element attribute "class" for #2 element by using "getElementAttribute" command

always response will be like

Response received: {"response":{"sessionId":null,"status":"unknown error","value":"Parsing error"}}

Q:

As it is a parsing error, i doubt i write the wrong joson for getElementAttribute

But i checked the msdn, i don't know where i was wrong.

Could your guys help to have a check on my code ?

http://msdn.microsoft.com/en-us/library/ie/dn768404%28v=vs.85%29.aspx

Source code

           //Execute a "get" command - Navigate to http://bing.com
            const string getCommand = @"
            {
                ""command"": {
                    ""name"": ""get"",
                    ""parameters"": {
                        ""url"": ""http://www.bing.com""
                    },
                    ""sessionId"": ""{sessionId}""
                }
            }";
            response = ExecuteCommand(getCommand, strSessionId);

            //"Page Loading Strategies" are not currently supported
            //"get" commands will return immediately and not wait for the page to load
            //The 20-second polling is added to wait for the page to load
            //This issue will be addressed and fixed in the next IEWebDriver release.
            WaitForPageToLoad(20, strSessionId);

            //Execute a "findElement" command - Find the Bing search field
            const string findElementCommand = @"
            {
                ""command"": {
                    ""name"": ""findElement"",
                    ""parameters"": {
                        ""locator"": ""css selector"",
                        ""value"": ""input[name='go']""
                    },
                    ""sessionId"": ""{sessionId}""
                }
            }";
            response = ExecuteCommand(findElementCommand, strSessionId);

            //Retrieve the ElementId from the response
            try
            {
                strElementId = response["response"]["value"]["id"];
            }
            catch (Exception e)
            {
                HandleError("Exception thrown when trying to access strResponse[\"response\"][\"value\"][\"id\"] from the response.", e);
            }

            //
            const string getAttrCommand = @"
            {
                ""command"": {
                    ""name"": ""getElementAttribute"",
                    ""parameters"": {
                        ""elementId"": ""{elementId}"",
                        ""name"":""title"",
                    },
                    ""sessionId"": ""{sessionId}""
                }
            }";
            response = ExecuteCommand(getAttrCommand, strSessionId, strElementId);




Viewing all articles
Browse latest Browse all 3527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>