前段时间我编辑了java selenium standalone的2.5.3版,以删除在从cookie所属的域加载页面之前尝试设置cookie时出现的错误消息“无法设置cookie”。该修改涉及编辑一些javascript以删除错误检查。
是否有可能在selenium 3.7.1中对java build进行类似的修改以改变java chrome?
目前我正在使用以下maven依赖项。我还没有修改过开源。
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.1</version>
</dependency>
我很想知道为什么selenium处理cookie的方式与浏览器不同。在浏览器上加载页面时,cookie在第一次加载页面时已经可用。对于selenium,cookie仅在首次加载给定域页面后才可用,然后需要第二次加载给定域页面才能识别cookie。
我认为必须有一些逻辑上的理由说明为什么必须以这种方式实现。有谁知道为什么?
我继续研究改良硒3.7.1:
我发现错误消息l [25] =“无法设置cookie”;在selenium github code
中的以下java和javascript文件中grep -rnw './' -e "unable to set cookie"
./javascript/atoms/error.js:142: UNABLE_TO_SET_COOKIE: 'unable to set cookie',
./javascript/node/selenium-webdriver/test/lib/error_test.js:61: test('unable to set cookie', error.UnableToSetCookieError);
./javascript/node/selenium-webdriver/test/lib/error_test.js:115: test(error.UnableToSetCookieError, 'unable to set cookie');
./javascript/node/selenium-webdriver/test/lib/error_test.js:189: test('unable to set cookie', error.UnableToSetCookieError);
./javascript/node/selenium-webdriver/lib/error.js:474: ['unable to set cookie', UnableToSetCookieError],
./java/client/src/org/openqa/selenium/remote/ErrorCodes.java:245: .add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
./javascript / node / selenium-webdriver / lib / error.js:474具有以下代码
/**
* A request to set a cookie’s value could not be satisfied.
*/
class UnableToSetCookieError extends WebDriverError {
/** @param {string=} opt_error the error message, if any. */
constructor(opt_error) {
super(opt_error);
}
} has the
./ java / client / src / org / openqa / selenium / remote / ErrorCodes.java:245具有以下代码
public static final int UNABLE_TO_SET_COOKIE = 25;
.add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
Cleary UnableToSetCookieException可能很重要。所以我对以下内容进行了抨击
grep -rnw './' -e "UnableToSetCookieException"
./java/client/src/org/openqa/selenium/remote/ErrorCodes.java:45:import org.openqa.selenium.UnableToSetCookieException;
./java/client/src/org/openqa/selenium/remote/ErrorCodes.java:245: .add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
./java/client/src/org/openqa/selenium/BUCK:128: 'UnableToSetCookieException.java',
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:25:public class UnableToSetCookieException extends WebDriverException {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:26: public UnableToSetCookieException() {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:29: public UnableToSetCookieException(String message) {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:33: public UnableToSetCookieException(Throwable cause) {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:37: public UnableToSetCookieException(String message, Throwable cause) {
./java/client/test/org/openqa/selenium/remote/ErrorHandlerTest.java:54:import org.openqa.selenium.UnableToSetCookieException;
./java/client/test/org/openqa/selenium/remote/ErrorHandlerTest.java:460: exceptions.put(ErrorCodes.UNABLE_TO_SET_COOKIE, UnableToSetCookieException.class);
显然,以下类会抛出cookie异常
/**
* Thrown when a driver fails to set a cookie.
*
* @see org.openqa.selenium.WebDriver.Options#addCookie(Cookie)
*/
public class UnableToSetCookieException extends WebDriverException {
public UnableToSetCookieException() {
}
public UnableToSetCookieException(String message) {
super(message);
}
但是我还没有理解这与生成错误的addCookie方法有什么关系。
driver.manage().addCookie(aCookie);
我将继续更新我的研究,因为我了解更多...