Webex training notes:
7/10/15
select the web element, right click -> select inspect by firepath->show absolute xpath.
driverobj.findElement(By.xpath("<>");
xpath = //<tag name>[@<attribute name>='<value>'] ....... Since we have picked name attribute here, the inspect element with this xpath will highlight all 3 checkboxes.
Following could be used:
ends-with
contains
Select <object name> = new Select(<web Element>);
Ex: Select dd1= new Select(driver.findElement(By.name("subject"));
dd1.selectIndex(1);
<object name>.selectByIndex("<value>");
<object name>.selectByValue("<value>")
<object name>.selectByVisibleText("<value>");
Lets suppose you wanted to select the last value of drop down, make use of index numders...index starts from 0. But you if you wanted to click the last but one drop down value, you need to know the total number of values in the drop down. To do that activity do the following.
<object name>.getOptions().size() === gives the total number of values in drop down.
xpath = //table[@class='fd']/td[@class='gfhy']
/ ---- use this if the element is direct child
xpath = //table[@class='fd']//a[@class='asd']
<tc>
--
<td class='sdf']
<a class ='dfs' href='#']Program</a>
--
--
</td>
--
--
</table>//td[@class='sdf']/a[@class='dfs' and text() = 'Program]
xpath = //table
- How to send encoded value to Password field...?
- Source:
http://blargon7.com/selenium_docs/04_selenese_commands.html
To find list of commands that we can use in Selenium to locate an object. Its really good.
7/10/15
- We have 8 locators, using which selenium webdriver identifies the web element.
- Using any one of the locators one shouldbe able to identify/locating element in a web page.
- <driverobject>.findElement(By.name("email_to[]")).click(); ---here name is one of the locators.
- Right click on the object and select inspect by firebug. Especially html script will be seen, when you select the code it will highlight the related area in the web page.
- If the attribute is common across multiple web elements, then we use firepath - xpath.
select the web element, right click -> select inspect by firepath->show absolute xpath.
driverobj.findElement(By.xpath("<>");
- If absolute reference is not working we need to go with relative reference(using // in the xpath).
- The brower that gets loaded using the script, using that we will not be able to inspect the element, because the script uses the default settings of browser. Additional settings that user does will not have impact on the script. To include your settings, we need to create profile using setproperty.
- Xpath could be created as to make sure it matches related properties that we mention in it, like we do using regular expression.
xpath = //<tag name>[@<attribute name>='<value>'] ....... Since we have picked name attribute here, the inspect element with this xpath will highlight all 3 checkboxes.
- xpath = //<tag name>[@<attribute name>='<value>'] [1] --- this will locate the first element with the same attribute.
- We can join two conditions using and
- Use Higlight, adjacent to Xpath section in inspect by Firepath window, when you click Highlight it will show the web element that xpath is refering too. That way you can validate the xpath, whether its pointing out to the proper web element. Dont forget to enter xpath in the field.
- Regular Expression in xpath:
Following could be used:
ends-with
contains
- Dropdown:
Select <object name> = new Select(<web Element>);
Ex: Select dd1= new Select(driver.findElement(By.name("subject"));
dd1.selectIndex(1);
<object name>.selectByIndex("<value>");
<object name>.selectByValue("<value>")
<object name>.selectByVisibleText("<value>");
Lets suppose you wanted to select the last value of drop down, make use of index numders...index starts from 0. But you if you wanted to click the last but one drop down value, you need to know the total number of values in the drop down. To do that activity do the following.
<object name>.getOptions().size() === gives the total number of values in drop down.
- xpath:
xpath = //table[@class='fd']/td[@class='gfhy']
/ ---- use this if the element is direct child
xpath = //table[@class='fd']//a[@class='asd']
- xpath:
- contains
- text() --- see i have come across a scenario where I need to select a text that is a hyperlink. Here keep in mind text was not a attribute.
<tc>
--
<td class='sdf']
<a class ='dfs' href='#']Program</a>
--
--
</td>
--
--
</table>//td[@class='sdf']/a[@class='dfs' and text() = 'Program]
xpath = //table
- How to send encoded value to Password field...?
- Source:
http://blargon7.com/selenium_docs/04_selenese_commands.html
To find list of commands that we can use in Selenium to locate an object. Its really good.
No comments:
Post a Comment