我一直关注以下2个教程网站:
我正在尝试自动化登录页面,但总是卡在“下一步”按钮以进入下一页。
我正在使用:
下面是“下一步”按钮的HTML片段。
<button type="submit" class="btn btn--block btn--raised primary" white--text="" style="position: relative;">
<div class="btn__content">Next</div>
</button>
package newpackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class T2 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\struong\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
String baseUrl = "https://vertical.vappcenter.com/login";
driver.get(baseUrl);
// Get the WebElement corresponding to the Email Address(TextField)
WebElement Email = driver.findElement(By.id("email"));
// Type in an email address
Email.sendKeys("struong@vertical.com");
// Find the Next button and click it
WebElement bNext = driver.findElement(By.className("btn_content"));
// Using click method to click Next
bNext.click();
}
}
我收到错误:
_在5146端口启动ChromeDriver 2.32.498550(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a) 仅允许本地连接。 2017年10月26日下午3:47:13 org.openqa.selenium.remote.ProtocolHandshake createSession 信息:检测到的方言:OSS 线程“main”中的异常org.openqa.selenium.NoSuchElementException:没有这样的元素:无法定位元素:{“method”:“class name”,“selector”:“btn_content”} (会话信息:chrome = 62.0.3202.62) (驱动程序信息:chromedriver = 2.32.498550(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform = Windows NT 10.0.15063 x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:0毫秒 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'3.6.0',修订版:'6fbf3ec767',时间:'2017-09-27T16:15:26.402Z' 系统信息:主机:'STRUONG-DT',ip:'172.18.11.10',os.name:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'9 “ 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能[{mobileEmulationEnabled = false,hasTouchScreen = false,platform = XP,acceptSslCerts = true,webStorageEnabled = true,browserName = chrome,takesScreenshot = true,javascriptEnabled = true,platformName = XP,setWindowRect = true,unexpectedAlertBehaviour =,applicationCacheEnabled = false, rotate = false,networkConnectionEnabled = false,chrome = {chromedriverVersion = 2.32.498550(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),userDataDir = C:\ Users \ struong \ AppData \ Local \ Temp \ scoped_dir7400_24258},takesHeapSnapshot = true,pageLoadStrategy = normal,unhandledPromptBehavior =,databaseEnabled = false,handlesAlerts = true,version = 62.0.3202.62,browserConnectionEnabled = false,nativeEvents = true,locationContextEnabled = true,cssSelectorsEnabled = true}] 会议ID:eb9bec8a6c5768eb31c3168d80b3831d ***元素信息:{使用=类名,值= btn_content} at java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base / jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在java.base / java.lang.reflect.Constructor.newInstance(Constructor.java:488) 在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214) 在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) 在org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) 在org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82) 在org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45) 在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164) 在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586) 在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:356) at org.openqa.selenium.remote.RemoteWebDriver.findElementByClassName(RemoteWebDriver.java:442) 在org.openqa.selenium.By $ ByClassName.findElement(By.java:391) 在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348) at newpackage.T2.main(T2.java:26)_
答案 0 :(得分:0)
正如错误所示,硒无法找到元素。您可以使用显示为:
的文本查找元素By.XPath("//button[.= 'Next']")