Am versuchen, unten beschriebenen Schritte auf der Website zu automatisieren - wwww.snapdeal.com (1) Melden Sie sich bei der Website (2) Wählen Sie Mobiles> Smartphones (3) Wählen Sie ein Smartphone-Modell (4) gehen auf die Zahlung (5) Bei der Zahlung Bildschirm, geben Sie die Kreditkarte No (6) Wählen Sie die Karte Ablaufdatum (Monat & Jahr)Selen Eklipse - DropDown Handling - Fehlgeschlagen
Schritte 1 bis 5 sind vergangen, aber Schritt 6 versagt. Das System hat das Dropdown-Feld nicht identifiziert und konnte daher nicht auswählen.
unten Wege Haben Sie versucht, aber alle // METHODE 1 = SELECT-Klasse versagen - FAILED // DROWDOWN Auswahlmethode Wählen Sie mit - PROBLEM DROPDOWN VALUES ARBEITS SELECT TAG SO SELECT KLASSE, DIE NICHT NICHT // METHODE 2 - uNTER VERWENDUNG KLICKEN UND SENDKEYS - FAILED // METHODE 3 - ACTION-Klasse - Fehlgeschlagen -.. Fehler „Element sein sollte "wählen", sondern wurde "div" gezeigt wird
Bitte helfen
unten ist die Code und auch angehängter Link für die HTML-Webelement-Eigenschaften des Feldes "MM"
package basic;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.JavascriptExecutor;
import java.sql.Driver;
import java.util.Set;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.interactions.*;
import org.openqa.selenium.Alert;
public class SnapDeal{
public static void main(String[]args) throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\hp\\workspace\\Selenium\\browser\\
chromedriver.exe");
WebDriver Snap = new ChromeDriver();
Snap.get("https://www.snapdeal.com/"); //log into - www.snapdeal.com
Thread.sleep(3000);
Snap.manage().window().maximize(); // maximze the window
Thread.sleep(2000);
Snap.findElement(By.xpath(".//*[@id='sdHeader']/div[4]/div[2]/div/div[3]/div[3]
/div/span[1]")).click(); // click on sign-in
Thread.sleep(1000);
Snap.findElement(By.xpath("//a [@href='https://www.snapdeal.com/login']")).click(); // click on sign-in
Thread.sleep(1000);
Snap.switchTo().frame("loginIframe"); // switch to child pop up window
Snap.findElement(By.id("userName")).sendKeys("9841490130"); // enter the mobile no
Snap.findElement(By.id("checkUser")).click(); //click proceed
Thread.sleep(1000);
Snap.findElement(By.xpath(".//*[@id='j_password_login_uc']")).sendKeys("badri1984"); // enter the password
Snap.findElement(By.id("submitLoginUC")).click();
Thread.sleep(3000);
Snap.findElement(By.xpath(".//*[@id='leftNavMenuRevamp']/div[1]/div[2]/ul/li[2]/a/span[2]")).click(); // click on mobiles
Snap.findElement(By.xpath(".//*[@id='category2Data']/div[1]/div/div/p[2]/a/span")).click(); // click smartphones
JavascriptExecutor AK = (JavascriptExecutor)Snap;// import JavascriptExecutor interface
AK.executeScript("scroll(0,700)"); //scroll down the window
Snap.findElement(By.xpath(".//*[@id='662623821571']/div[3]/div[1]/a/p")).click();//click on a model, new child tab opened.
String Parwindow = Snap.getWindowHandle(); // capture the parent window id as string "Parwindow"
System.out.println("PARENT WINDOW ID ID " + Parwindow); // Print the Parent Window ID
Set<String> allwindows = Snap.getWindowHandles(); // Capture all the window ids as String allwindows
int count = allwindows.size(); // capture the count of windows ids as int count
for(String Child : allwindows){ // applying "FOR EACH" loop, declaring String Child equals all windows(all windows ids)
if (!Parwindow.equalsIgnoreCase(Child)){ // applying if condition as if parent window id not equals to windows ids captured in String child)
Snap.switchTo().window(Child); // switching to child window using the child window id
System.out.println("CHILD WINDOW IS " + Child); // printing the child window id
Thread.sleep(2000);
JavascriptExecutor SK = (JavascriptExecutor)Snap;// import JavascriptExecutor interface
SK.executeScript("scroll(0,400)");//scroll down the window
Thread.sleep(1000);
Snap.findElement(By.id("buy-button-id")).click();// click on buy bottom
Thread.sleep(2000);
JavascriptExecutor ABN = (JavascriptExecutor)Snap;// import JavascriptExecutor interface
ABN.executeScript("scroll(0,1000)");// Scroll Down
Thread.sleep(1000);
Snap.findElement(By.id("make-payment")).click();// click on payment
Thread.sleep(1000);
JavascriptExecutor NY = (JavascriptExecutor)Snap;// import JavascriptExecutor interface
NY.executeScript("scroll(0,800)");// Scroll down and click on buy bottom
Thread.sleep(1000);
Snap.findElement(By.name("card_number_mask")).sendKeys("4176092389357621"); // enter the card no
// METHOD 1 = USING SELECT CLASS - FAILED
//DROWDOWN SELECTION METHOD USING SELECT - PROBLEM DROPDOWN VALUES ARE NOT HAVING SELECT TAG SO SELECT CLASS NOT WORKING.HOW TO SELECT THE DROPDOWN?
/*WebElement Date = Snap.findElement(By.id("CS2"));
Select Date_D = new Select(Date);
WebElement Date_Value = Date_D.getFirstSelectedOption();
System.out.println("Selected Value for Date is " + Date_Value.getText());
Date_D.selectByIndex(9);*/
// METHOD 2 - USING CLICK AND SENDKEYS - FAILED
//Snap.findElement(By.id("CS2")).click();
//Snap.findElement(By.id("CS2")).sendKeys("09");
// METHOD 3 - USING ACTION CLASS - FAILED - "Element should have been "select" but was "div"
/*Actions act = new Actions(Snap);
act.moveToElement(Snap.findElement(By.id("CS2")));
act.click();
act.sendKeys("09");
WebElement Month = Snap.findElement(By.id("CS3"));
Select Month_MM = new Select(Month);
Month_MM.selectByValue("17");
Thread.sleep(2000);
Month_MM.selectByVisibleText("YY");
Thread.sleep(2000);
Month_MM.selectByVisibleText("19");
Thread.sleep(2000);
Snap.findElement(By.name("cvvValidate")).sendKeys("007");
Thread.sleep(1000);
WebElement Pay_Button = Snap.findElement(By.id("creditcard-continue"));
Pay_Button.getText();
System.out.println("Pay button text is " + Pay_Button.getText());
}
}}}
enter image description here enter image description here
Ich habe Ihre Frage nicht vollständig gesehen, aber ich denke, dass dies ein Timing-Problem sein könnte. Können Sie alle thread.sleep entfernen und implizite warten, nachdem der Treiber initiiert wurde? WebDriver-Treiber = new FirefoxDriver(); driver.manage(). Timeouts(). ImplicitlyWait (20, TimeUnit.SECONDS); –
@ santhosh, danke für deine Antwort aber schon versucht implizit warten aber immer noch scheitern. Das Problem ist, dass Selen das "MM" -Webelement selbst nicht identifiziert. – badri
Können Sie mir bitte die Navigation Schritte von Snapdeal Homepage sagen. –