小编Deb*_*anB的帖子

线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由:系统属性设置

Exception in thread "main" java.lang.IllegalStateException : The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html  
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)  
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)  
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)  
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)   at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)   
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)    
at practise_locators.DatePicker.main(DatePicker.java:11)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

package practise_locators;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DatePicker {

    public static void main(String[] args){
        WebDriver driver = new ChromeDriver();
        System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
        driver.get("https://www.google.com");
    }

}
Run Code Online (Sandbox Code Playgroud)

java selenium webdriver selenium-chromedriver selenium-webdriver

2
推荐指数
1
解决办法
3万
查看次数

java.lang.NullPointerException 当使用带有 Java 的黄瓜 junit 通过步骤定义文件执行黄瓜特征文件时

在使用 junit 和 Java 运行黄瓜功能文件时,我收到一个 NULL 指针异常。我无法理解为什么会出现此异常。
这是我用java编写的步骤定义文件。

import java.util.List;
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 pageObjects.CartPage;
import pageObjects.Checkoutpage;
import pageObjects.HomePage;
import pageObjects.ProductListingPage;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;

public class EndtoEndTest {

WebDriver driver;

@Given("^User is on Homepage$")
public void user_is_on_Homepage() throws Throwable {

    System.setProperty("webdriver.chrome.driver", "C:\\Users\\Downloads\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://www.shop.demoqa.com");
    driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
    driver.manage().window().maximize();


}

@When("^he searches for \"([^\"]*)\"$")
public void he_searches_for(String arg1) throws Throwable {

    HomePage home = new HomePage(driver);
    home.perform_Search(arg1);
}

@When("^Choose …
Run Code Online (Sandbox Code Playgroud)

java selenium webdriver cucumber-junit selenium-webdriver

2
推荐指数
1
解决办法
8798
查看次数

通过Selenium WebDriver从JavascriptExecutor接口使用executeScript方法时,arguments [0]和arguments [1]是什么意思?

是什么arguments[0]以及arguments[1]使用时的意思是executeScript()方法从JavascriptExecutor通过硒webdriver的接口,什么是的目的arguments[0]在下面的代码。

javaScriptExecutor.executeScript("arguments[0].click()", webElement);
Run Code Online (Sandbox Code Playgroud)

javascript java selenium webdriver selenium-webdriver

2
推荐指数
1
解决办法
6595
查看次数

我的问题是关于Selenium的css选择器的find元素

我正在使用Selenium通过css选择器查​​找web元素.当我硬编码时,它的工作原理如下.

driver.findElement(By.cssSelector("div[aria-label=\"2018-10-17 Shared Google Drive Folder\"]")).getAttribute("data-id");
Run Code Online (Sandbox Code Playgroud)

但是,如果我想根据下面的日期自定义css选择器字符串,它会抛出一个错误:

org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified
Run Code Online (Sandbox Code Playgroud)

我打印出cssFormatString,它看起来与上面的硬编码完全相同.谁能告诉我哪里出错了?

// Customized cssFormatString code
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String strDate = dateFormat.format(date);
String cssFormatString = "div[aria-label=\\\"" + strDate +  " Shared Google Drive Folder\\\"]";
driver.findElement(By.cssSelector(cssFormatString)).getAttribute("data-id");
Run Code Online (Sandbox Code Playgroud)

java string selenium css-selectors selenium-webdriver

2
推荐指数
1
解决办法
187
查看次数

在 Selenium Python 中使用 Keys.PAGE_DOWN 滚动

你好每个人都可以帮助我滚动https://www.grainger.com/category/black-pipe-fittings/pipe-fittings/pipe-tubing-and-fittings/plumbing/ecatalog/N-qu1?searchRedirect=产品

我想滚动这个使用

actions = ActionChains(browser)
actions.send_keys(Keys.PAGE_DOWN)
actions.perform()
Run Code Online (Sandbox Code Playgroud)

直到它到达滚动的底部,在那里它会找到一个元素“加载更多”

loadMoreButton = browser.find_element_by_css_selector(
                        ".btn.list-view__load-more.list-view__load-more--js")
loadMoreButton.click()
Run Code Online (Sandbox Code Playgroud)

然后庞塞单击加载更多按钮,它必须再次执行滚动操作,然后再次执行加载更多操作,直到加载更多按钮不可用。

我必须使用此页面向下操作,因为在页面滚动到元素之前元素不会加载,如果有人可以提出一些解决方案将有很大帮助

python lazy-loading web-scraping selenium-webdriver webdriverwait

2
推荐指数
1
解决办法
5987
查看次数

Chromedriver:如何使用 selenium 翻译页面?

我需要在 Chrome 浏览器中使用 selenium 将页面从日语翻译成英语。我尝试了不同的方法,示例代码片段之一如下

import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Main {

    private WebDriver driver=null;
    WebDriverLoad a;

    @Test
    public void successfulDesignerLogin() throws Exception{
//      final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//        capabilities.setJavascriptEnabled(true);
        String chromedriver =  "/dev/Saved/chromedriver";
        System.setProperty("webdriver.chrome.driver",chromedriver);

        ChromeOptions options = new ChromeOptions();
        options.addArguments("--lang=en-ca");
        //Map<String, Object> prefs = new HashMap<String, Object>();
        //prefs.put("intl.accept_languages", "en,en_US");
        //options.setExperimentalOption("prefs", prefs);


       ChromeDriver driver = new ChromeDriver(options);
       driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
       driver.get("https://www.bbc.com/japanese");
       driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
       driver.close();


}
}
Run Code Online (Sandbox Code Playgroud)

我尝试了几种解决方案options.addArguments options.setExperimentalOption,但没有任何效果,任何人都可以建议我解决方案是什么

selenium google-translate translate selenium-chromedriver

2
推荐指数
1
解决办法
4895
查看次数

如何修复 AttributeError:“NoneType”对象没有属性“click”

如何解决错误AttributeError: \'NoneType\' object has no attribute \'click\'?它的失败在于self.home.get_you_button().click(). 当我没有创建页面对象类时,它\xe2\x80\x99s 工作正常...它单击“You”按钮,没有任何错误,但通过使用 POM,它\xe2\x80\x99s 失败。网址是https://huew.co/

\n\n

代码试验:

\n\n
from selenium.webdriver.support import expected_conditions\nfrom selenium.webdriver.support.wait import WebDriverWait\n\nclass HomePage():\n\n    def __init__(self,driver):\n        self.driver = driver\n\n    def wait_for_home_page_to_load(self):\n        wait =WebDriverWait(self.driver,30)\n        wait.until(expected_conditions.visibility_of(self.driver.find_element_by_tag_name(\'html\')))\n\n    def get_you_button(self):\n\n        try:\n            element = self.driver.find_element_by_xpath("//div[@class=\'desktop-public-header\']/a[@ng-controller=\'UserNavigationInteractionCtrl\'][6]")\n\n        except:\n            return None\n
Run Code Online (Sandbox Code Playgroud)\n

python selenium python-3.x selenium-webdriver webdriverwait

2
推荐指数
1
解决办法
2万
查看次数

如何在python selenium中设置Chrome实验选项same-site-by-default-cookie

我想这应该有效:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('same-site-by-default-cookies', 'true')
driver = webdriver.Chrome(chrome_options=options)
Run Code Online (Sandbox Code Playgroud)

启用为未来 chrome 版本计划的相同站点 cookie 限制。不是,有错误:

selenium.common.exceptions.InvalidArgumentException: 
Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: same-site-by-default-cookies
Run Code Online (Sandbox Code Playgroud)

我可以使用 chrome://flags 手动更改选项并查看它是否正常工作。但是我想自动化它并运行测试脚本来查看它。

这里有 java 代码:https : //groups.google.com/forum/#!topic/ chromedriver-users/ cI8hj7eihRo 可以做到,但我不确定如何将其传输到 python。

是否有任何参考资料可以帮助我设置此选项或其他选项?

selenium google-chrome python-3.x selenium-chromedriver samesite

2
推荐指数
1
解决办法
6598
查看次数

如何使用 Python 查找 Pycharm 的版本

我有一个程序可以从我的系统中获取版本(selenium、python 和 chrome),并将其与在线最新版本进行比较。

这是从我的系统获取 pythons 版本的代码

    pythonVersion = platform.python_version()
    finalVersion = "Python " + pythonVersion
Run Code Online (Sandbox Code Playgroud)

现在我的主要问题是尝试使用代码获取 Pycharms 版本。如果有人知道如何做到这一点,那将会很有帮助

python version pycharm

2
推荐指数
1
解决办法
6664
查看次数

Selenium 中的 execute_script() 有什么作用

browser.execute_script("window.open('about:blank', 'tab2');")
browser.switch_to.window("tab2")
browser.get('http://bing.com')
Run Code Online (Sandbox Code Playgroud)

我在网上搜索在 python 中使用 selenium 打开新选项卡的方法,并且ctrl + 的方法t不适用于 chrome,所以我偶然发现了上面的一段代码,但是我无法理解 'excute_script' 的作用。

javascript python selenium webdriver selenium-webdriver

2
推荐指数
1
解决办法
1734
查看次数