So I'm testing adding an item to a cart, but realistically I want to pick the 1st Item if present and else if select the second but there's no list on https://www.prana.com/men/tops/shirts.html for the items. So I went the css selector for each of the images. To also still have the ability to have multiple items I wanted to use if- else if statements to decide between the Items. I have:
if (driver.findElement(By.cssSelector("a[title='Weathered Blu22e']")).isDisplayed()) {driver.findElement(By.cssSelector("a[title='Weathered Blue']")).click();} else if (driver.findElement(By.cssSelector("a[title='Equinox Blue']")).isDisplayed ) {driver.findElement(By.cssSelector("a[title='Weathered Blue']")).click();}
the first line that has "Blu22e" is not a correct CSS title but Blue is... when I have "blue" it selects the item correctly but When I put in Blu22e ( to do a negative test and go to the else if statement I see this error:
no such element: unable to locate such an element.
Any ideas how I can negative test the first line? I want it to skip that and move on to the next statement Sorry for lack of knowledge I am an intern and going to school still so my Java isnt up to par.
Aucun commentaire:
Enregistrer un commentaire