In this article we are going to see the functions to work with a selected item in selenium web driver. I am using c#(VS 2010) here.
From my previous post we can see how to select an element.In this way we can work with the item as well as inner item elements. So, for selection we use the code
private IWebElement element;
private SelectElement myElement ;
//In the test function we will use following code
element = driver.FindElement(By.XPath("String"));
myElement = new SelectElement(element);
myElement.DeselectAll();//This is optional, for safe operation
myElement.SelectByIndex(12);
After selection, we can performs following actions
- To Get a value(true/false) indicating whether or not selected element has multiple selectivity ( like multiple check box, or multiple combo item selection)
myElement.IsMultiple// provides true/false output
- To Clear the content of selected element.
myElement.SelectedOption.Clear();
- To Click selected element.
myElement.SelectedOption.Click();
-To Get a value(true/false) indicating whether or not selected element is selected
myElement.SelectedOption.Selected;
-To Get a value(true/false) indicating whether or not selected element is displayed.
myElement.SelectedOption.Displayed;
-To Get a value(true/false) indicating whether or not selected element is enabled.
myElement.SelectedOption.Enabled;
- To Get integer(in pixel) value of the Vertical length of selected element
myElement.SelectedOption.Size.Height;
- To Get integer(in pixel) value of the Horizontal length of selected element
myElement.SelectedOption.Size.Width;
-To Get the tag name of selected element.
myElement.SelectedOption.TagName;
-To write text into the selected element(i.e- text box)
myElement.SelectedOption.SendKeys("String");
-To Submit selected element to the web server.(i.e- log In button)
myElement.SelectedOption.Submit();
-To Get the Inner Text of selected element(with no leading or trailing whitespace, collapsed other whitespaces)
myElement.SelectedOption.Text;
-To Get a value(true/false) indicating whether selected element is empty(use this to find an element's existence)
myElement.SelectedOption.Location.IsEmpty;
-To Get the x-coordinate of Selected element(in Integer)
myElement.SelectedOption.Location.X;
-To Get the y-coordinate of Selected element(in Integer)
myElement.SelectedOption.Location.Y;
Note : The basic difference to use "element" and "selectElement" is, element can be found from a page and work directly with a web component, where as selectElement ca work with page's web components as well as with there's inner items.
Thanks....:) I will try to provide an example using those in separate post.
From my previous post we can see how to select an element.In this way we can work with the item as well as inner item elements. So, for selection we use the code
private IWebElement element;
private SelectElement myElement ;
//In the test function we will use following code
element = driver.FindElement(By.XPath("String"));
myElement = new SelectElement(element);
myElement.DeselectAll();//This is optional, for safe operation
myElement.SelectByIndex(12);
After selection, we can performs following actions
- To Get a value(true/false) indicating whether or not selected element has multiple selectivity ( like multiple check box, or multiple combo item selection)
myElement.IsMultiple// provides true/false output
- To Clear the content of selected element.
myElement.SelectedOption.Clear();
- To Click selected element.
myElement.SelectedOption.Click();
-To Get a value(true/false) indicating whether or not selected element is selected
myElement.SelectedOption.Selected;
-To Get a value(true/false) indicating whether or not selected element is displayed.
myElement.SelectedOption.Displayed;
-To Get a value(true/false) indicating whether or not selected element is enabled.
myElement.SelectedOption.Enabled;
- To Get integer(in pixel) value of the Vertical length of selected element
myElement.SelectedOption.Size.Height;
- To Get integer(in pixel) value of the Horizontal length of selected element
myElement.SelectedOption.Size.Width;
-To Get the tag name of selected element.
myElement.SelectedOption.TagName;
-To write text into the selected element(i.e- text box)
myElement.SelectedOption.SendKeys("String");
-To Submit selected element to the web server.(i.e- log In button)
myElement.SelectedOption.Submit();
-To Get the Inner Text of selected element(with no leading or trailing whitespace, collapsed other whitespaces)
myElement.SelectedOption.Text;
-To Get a value(true/false) indicating whether selected element is empty(use this to find an element's existence)
myElement.SelectedOption.Location.IsEmpty;
-To Get the x-coordinate of Selected element(in Integer)
myElement.SelectedOption.Location.X;
-To Get the y-coordinate of Selected element(in Integer)
myElement.SelectedOption.Location.Y;
Note : The basic difference to use "element" and "selectElement" is, element can be found from a page and work directly with a web component, where as selectElement ca work with page's web components as well as with there's inner items.
Thanks....:) I will try to provide an example using those in separate post.
No comments:
Post a Comment