Reputation: 281
Scenario - Valid login to www.homeshop18.com and then from the Digital Menu select "Samsung". The results are displayed and now I need to choose another brand - Micromax from the Brand section (displayed at the left side of the page) which requires scrolling and selecting Micromax.
Issue:
Though the xpath of Micromax is correct which is //*[@id='filter_1Option_12']//div[@class='ez-checkbox'] but I see during run time of the script - some other brand is getting selected instead of micromax. Kindly advise.
//Class for valid login to www.homeshop18.com
public class HomeShop_Login_Test
{
@FindBy(xpath="//a[@id='signInHeaderLink']") WebElement SignIn_Link;
@FindBy(xpath=".//input[@id='emailId']") WebElement Email;
@FindBy(xpath=".//input[@id='existing_user_radio']") WebElement Existing_User_Radio;
@FindBy(xpath=".//input[@id='new_user_radio']") WebElement New_User_Radio;
@FindBy(xpath=".//input[@id='password']") WebElement Password;
@FindBy(xpath=".//a[@id='signin']") WebElement SignIn_Button;
@FindBy(xpath="//a[@title='Close']") WebElement Close_Home;
public void Login_Valid()
{
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement SignIn_Link = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@id='signInHeaderLink']")));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click()", SignIn_Link);
Email.sendKeys("[email protected]");
boolean selected;
selected = New_User_Radio.isSelected();
if(selected)
{
Existing_User_Radio.click();
}
Password.sendKeys("xxx");
SignIn_Button.click();
}
//Class to choose Samsung from Digital menu
public class Browse_Samsung_Mobile
{
@FindBy(xpath="//*[@id='CategoryMenu1']//a[text()='Digital']") WebElement Digital_Menu;
@FindBy(xpath="//*[@id='CategoryMenu1']//a[@title='Samsung']") WebElement Samsung_SubMenu;
@FindBy(xpath="//*[@id='filter_1Option_19']//span[@class='selected_filter_img']") WebElement Micromax;
public void Browse_Samsung()
{
WebDriverWait wait = new WebDriverWait(driver, 30);
Actions act = new Actions(driver);
act.moveToElement(Digital_Menu).perform();
act.click(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='CategoryMenu1']//a[@title='Samsung']")))).build().perform();
//WebElement Micromax = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='filter_1Option_12']//span[@class='selected_filter_img']")));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click()", Micromax);
}
}
//class to call above two classes
public class Validate_Browse_Samsung_Mobile
{
WebDriver driver;
@Test
public void Validate_Browse()
{
driver = BrowserFactory.getBrowser("Firefox");
driver.get(DataProviderFactory.getConfig().getURL());
HomeShop_Login_Test login = PageFactory.initElements(driver, HomeShop_Login_Test.class);
login.Login_Valid();
Browse_Samsung_Mobile browse = PageFactory.initElements(driver, Browse_Samsung_Mobile.class);
browse.Browse_Samsung();
}
}
Upvotes: 0
Views: 292
Reputation: 23805
You should try with their name using title
attribute as below :-
WebElement micromax = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("a[title ~= "Micromax"] input")));
Upvotes: 1
Reputation: 52665
You should use following XPath
to choose proper check-box:
//a[@title="GSM Mobile Phones - Micromax"]/div/input
Upvotes: 0