我无法点击paytm的登录按钮。它将突出显示,但不会单击。
该代码在火狐中完美运行。您无法在 Chrome 浏览器中点击该链接。它没有显示任何错误或异常,只是无法单击。
下面是我的代码:
driver.get("https://paytm.com/");
WebElement LoginLink= driver.findElement(By.xpath("//*[contains(text(),'Log In/Sign Up')]"));
Highlight.highLightElement(driver, LoginLink);
LoginLink.click();
public class LoginPage {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
String url="https://paytm.com/";
driver.get(url);
Thread.sleep(5000);
WebElement Login=(WebElement) driver.findElement(By.className("_3ac-"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", Login);
}
}
driver.manage((.window((.maximize((;
driver.get("https://paytm.com/"(;
线程睡眠(2000(;
JavascriptExecutor je = (JavascriptExecutor( driver;
WebElement Login_Btn= driver.findElement(By.xpath("//*[contains(text((,'Log In/Sign Up'(]"((;
je.executeScript("arguments[0].scrollIntoView(true(;",Login_Btn(;
Login_Btn.click((;
以下是您问题的答案:
您可以使用以下代码块单击https://paytm.com/
Google Chrome 59.0
上的Log In/Sign Up
按钮:
注意:作为您问题的快速解决方案,我诱导了
Thread.sleep(5000);
,应替换为ExplicitWait
,即WebDriverWait
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Q45102095_PAYTM
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://paytm.com/");
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
Thread.sleep(5000);
WebElement login_button = driver.findElement(By.xpath("//div[@id='app']//div[normalize-space(text()) = 'Log In/Sign Up']"));
login_button.click();
}
}
让我知道这是否回答了您的问题。