java - Selenium Web driver select data from drop down by reading drop down value from excel sheet -
i trying select drop down value reading drop down value excel. tried following code however, not selecting value per data mentioned in excel sheet. me data populating correctly in respective field except gender drop down.
following screen shot of html code , ui:
following html code:
<td class="codetable last-cell" headers="n224aa-4-2"> <div id="widget___o3id7" class="dijit dijitreset dijitinline dijitleft codetable dijittextbox dijitcombobox" lang="en-us" role="listbox" dir="ltr" widgetid="__o3id7" aria-expanded="false"> <div class="dijitreset dijitright dijitbuttonnode dijitarrowbutton dijitdownarrowbutton dijitarrowbuttoncontainer" role="presentation" data-dojo-attach-point="_buttonnode, _popupstatenode" popupactive="true"> <input class="dijitreset dijitinputfield dijitarrowbuttoninner" type="text" role="presentation" readonly="readonly" tabindex="-1" value="▼ "> </div> <div class="dijitreset dijitvalidationcontainer"> <input class="dijitreset dijitinputfield dijitvalidationicon dijitvalidationinner" type="text" role="presentation" readonly="readonly" tabindex="-1" value="Χ "> </div> <div class="dijitreset dijitinputfield dijitinputcontainer"> <input id="__o3id7" class="dijitreset dijitinputinner" type="text" aria-haspopup="true" role="textbox" data-dojo-attach-point="textbox,focusnode" autocomplete="off" aria-required="true" tabindex="0" title="gender mandatory" size="1" value="male" aria-owns="__o3id7_popup" aria-activedescendant="__o3id7_popup1"> <input type="hidden" name="__o3id7" value="sx1"> </div> </div> </td>
i populated test data in excel sheet below "female" drop down value:
username password123 100000005 elena sawyerehde female
following code:
package com.access; import org.openqa.selenium.*; import org.openqa.selenium.chrome.chromedriver; import org.openqa.selenium.support.ui.select; import org.testng.assert; import org.testng.annotations.*; import java.io.fileinputstream; import jxl.sheet; import jxl.workbook; public class registration { static webdriver driver; @beforemethod public void setup() throws exception { system.setproperty("webdriver.chrome.driver", "c:\\directory\\chromedriver.exe"); driver = new chromedriver(); driver.manage().window().maximize(); thread.sleep(2000); } @test public void testcase1() throws exception { fileinputstream fi=new fileinputstream("c:\\file\\book2.xls"); workbook w=workbook.getworkbook(fi); sheet s=w.getsheet(0); driver.get("https://example.com"); try { (int = 0; < s.getrows(); i++) { //read data excel sheet string s1 = s.getcell(0,i).getcontents(); string s2 = s.getcell(1,i).getcontents(); string s3 = s.getcell(2,i).getcontents(); string s4 = s.getcell(3,i).getcontents(); string s5 = s.getcell(4,i).getcontents(); string s6 = s.getcell(5,i).getcontents(); driver.findelement(by.xpath("html/body/div[2]/form/input[1]")).sendkeys(s1); thread.sleep(2000); driver.findelement(by.xpath("html/body/div[2]/form/input[2]")).sendkeys(s2); thread.sleep(2000); driver.findelement(by.xpath("html/body/div[2]/a/span/span/span")).click(); thread.sleep(2000); assert.assertequals("testing hub", driver.findelement(by.xpath("//*[@id='app-banner']/div[1]/div/h2")).gettext()); thread.sleep(2000); driver.findelement(by.xpath("html/body/div[1]/div[4]/div[1]/div[4]/div/div[2]/div/div/div/span[1]")).click(); thread.sleep(2000); driver.findelement(by.xpath("html/body/div[1]/div[4]/div[3]/div[2]/div[3]/div[3]/div[1]/div/div[2]/div/div/div/span/span/span/span[2]")).click(); thread.sleep(1000); driver.findelement(by.xpath("html/body/div[4]/table/tbody/tr[2]/td[2]")).click(); thread.sleep(2000); driver.switchto().frame("iframe-curam_modaldialog_0"); thread.sleep(1000); driver.findelement(by.xpath("//*[@id='__o3id0']")).sendkeys(s3); thread.sleep(1000); driver.findelement(by.xpath("html/body/div[3]/form/div/div[5]/a[1]/span/span/span")).click(); thread.sleep(1000); assert.assertequals("there no matching items based on search criteria entered.", driver.findelement(by.xpath("html/body/div[3]/div/ul/li/div")).gettext()); thread.sleep(1000); driver.findelement(by.xpath("html/body/div[4]/div[2]/a/span/span/span")).click(); thread.sleep(2000); driver.findelement(by.xpath("html/body/div[3]/form/div/div[2]/div/table/tbody/tr[1]/td[1]/input")).sendkeys(s4); thread.sleep(1000); driver.findelement(by.xpath("html/body/div[3]/form/div/div[2]/div/table/tbody/tr[2]/td[1]/input")).sendkeys(s5); thread.sleep(1000); new select(driver.findelement(by.id("___o3id7"))).selectbyvalue(s6); thread.sleep(2000); } } catch(exception e) { system.out.println(e); } } }
as there no select tag in code pasted, using select
clicking dropdown won't help.
as per test script , html code id
value dropdown different.
//*[@id='widget___o3id7']
- used in xpath select dropdown, in html code id = "__o3id7"
.
try after changing them
its better share ui understand scenario , come conclusion
thanks sharing ui , html code.
driver.findelement(by.id("__o3id7")).click(); thread.sleep(1500); driver.findelement(by.xpath("//*[contains(text(),'female')]")).click();
replace select
statement , try codes. lets hope click 'female' drop down.
Comments
Post a Comment