【发布时间】:2018-09-01 06:45:15
【问题描述】:
我的代码首先让我登录 PayPal,然后登录 eBay 并导航到支付费用页面,然后使用 PayPal 结账。我无法单击/提交的最后一个“继续”按钮。我已经尝试过 xpath、id 和 class。我什至尝试发送 TAB 7x 直到 Continue 按钮,然后发送 Enter 但这不起作用。
我找到了这个讨论,但我不确定如何让它对我有用。 PayPal Sandbox checkout 'continue button' - Unable to locate element: - C# WebDriver
//Chrome WebDriver specific
System.setProperty("webdriver.chrome.driver", "C:\\automation\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize(); //maximise webpage
WebDriverWait wait = new WebDriverWait(driver, 20);
//navigate to Paypal
driver.get("https://www.paypal.com/uk/signin");
//wait 2.5s for the page to load
try {
Thread.sleep(2500);
}
catch (Exception e) {
e.printStackTrace();
}
WebElement paypalEmail = driver.findElement(By.id("email"));
paypalEmail.sendKeys("******");
//wait 2.5s for the page to load
try {
Thread.sleep(2500);
}
catch (Exception e) {
e.printStackTrace();
}
WebElement paypalSubmit = driver.findElement(By.id("btnNext"));
paypalSubmit.click();
String URL = ("https://www.paypal.com/uk/signin");
driver.get(URL);
WebElement form2 = driver.findElement(By.cssSelector(".main form"));
WebElement username = form2.findElement(By.id("password"));
username.sendKeys("******");
WebElement paypalSubmit2 = driver.findElement(By.id("btnLogin"));
paypalSubmit2.click();
//navigate to Ebay
driver.get("https://signin.ebay.co.uk/ws/eBayISAPI.dll?SignIn&ru=https%3A%2F%2Fwww.ebay.com%2F");
// Enter user name , password and click on Signin button
WebElement form = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#mainCnt #SignInForm")));
form.findElement(By.cssSelector("input[type=text][placeholder='Email or username']")).sendKeys("******");
form.findElement(By.cssSelector("input[type=password]")).sendKeys("******");
form.findElement(By.id("sgnBt")).click();
driver.get("http://cgi3.ebay.co.uk/ws/eBayISAPI.dll?OneTimePayPalPayment");
//WebElement Pay =
driver.findElement(By.xpath("//input[@value='Pay']")).click();
WebDriverWait wait2 = new WebDriverWait(driver, 15);
wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"confirmButtonTop\"]")));
driver.findElement(By.xpath("//*[contains(@id,'confirmButtonTop')]")).click();
}
}
【问题讨论】:
-
没用,是什么都没有发生还是有什么问题,是不是抛出了异常?
-
@Frank 道歉,页面在最后结账时就坐在那里。代码运行良好,IntelliJ 上没有抛出任何错误
-
Id 'confirmButtonTop' 是唯一的,你检查了吗?
-
@Frank 我实际上不确定如何检查它是否是唯一的。我检查了页面源,找不到任何“confirmButtonTop”。我检查了元素,只有那个。
-
这里解释:stackoverflow.com/q/22571267/6320173最好使用Chrome开发者工具。