尝试使用Selenium单击按钮时,如何得到InvalidSelectorException?

克劳德·巴斯蒂安(Claude Bastien)

我与Selenium合作非常陌生。我试图单击以下“选择”按钮:在此处输入图片说明

这是我的代码:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirstTest 
{
    private static WebDriver driver;

    public static void main(String[] args) throws Exception
    {
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.navigate().to("http://www.metro.ca/flyer/index.en.html");

        WebElement postalCodeInputBox = driver.findElement(By.name("postalcode"));
        postalCodeInputBox.sendKeys("L6R1A1");
        postalCodeInputBox.submit();

        String pageSource = driver.getPageSource();
        if(pageSource.contains("setstore btn"))
            System.out.println("setstore btn FOUND");

        WebElement selectButton = driver.findElement(By.className("setstore btn"));
        selectButton.click();
    }
}

图片确认“ setstore btn”在源中: 在此处输入图片说明

这是源代码中的setstore btn ”:在此处输入图片说明

派克·贝克

这很可能是由于您尝试在单个By.className()中搜索两个单独的类引起的。“ setstore”和“ btn”分别是自己的类。

尝试更换

WebElement selectButton = driver.findElement(By.className("setstore btn"));

WebElement selectButton = driver.findElement(new ByAll(By.className("setstore"), By.className("btn")));

另外,https://stackoverflow.com/a/16090160/1055102提供了另一个不错的选择。

WebElement selectButton = driver.findElement(By.cssSelector(".setstore.btn"));

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

selenium python,尝试单击按钮

来自分类Dev

如何使用Selenium Python单击文本按钮

来自分类Dev

如何使用Selenium和Java单击按钮?

来自分类Dev

如何使用 selenium python 单击按钮

来自分类Dev

如何使用 Selenium C# 单击按钮

来自分类Dev

当文本更改为其他内容时,如何使用Selenium和Python单击按钮?

来自分类Dev

使用 Selenium 和 Java 单击按钮时出现问题

来自分类Dev

在 Python 中使用 Selenium 单击按钮时遇到问题

来自分类Dev

当我尝试单击可扩展区域中的按钮时,出现OpenQA.Selenium.NoSuchElementException

来自分类Dev

NoSuchElementException:消息:尝试通过 Selenium 和 Python 单击 VISA 按钮时无法定位元素

来自分类Dev

ElementNotVisibleException:消息:尝试通过 Selenium 和 Python 单击按钮时元素不可交互错误

来自分类Dev

使用Selenium单击按钮Python

来自分类Dev

尝试单击导航按钮时,Espresso AmbiguousViewMatcherException

来自分类Dev

单击按钮时尝试创建imageView

来自分类Dev

如何使用Selenium单击网页上的打印按钮

来自分类Dev

使用Selenium,如何根据相关标签单击单选按钮

来自分类Dev

如何使用Selenium和Python 2.7单击表单中的按钮?

来自分类Dev

如何使用Selenium通过文本或值单击按钮?

来自分类Dev

如何单击使用<span>标记为Selenium Webdriver创建的按钮

来自分类Dev

如何使用Selenium和Python在iframe中单击按钮

来自分类Dev

如何使用Python + Selenium在警报中单击“确定”按钮

来自分类Dev

如何使用Selenium和Python单击“搜索”按钮?

来自分类Dev

如何使用Selenium在Python上单击iframe按钮?

来自分类Dev

如何使用python,selenium单击框架内的按钮?

来自分类Dev

使用Selenium,如何根据相关标签单击单选按钮

来自分类Dev

如何单击使用<span>标记为Selenium Webdriver创建的按钮

来自分类Dev

如何使用Selenium和Python单击确认按钮?

来自分类Dev

如何使用 selenium (Python) 单击 Alertify 对话框按钮

来自分类Dev

如何使用 python 和 selenium 单击此按钮

Related 相关文章

  1. 1

    selenium python,尝试单击按钮

  2. 2

    如何使用Selenium Python单击文本按钮

  3. 3

    如何使用Selenium和Java单击按钮?

  4. 4

    如何使用 selenium python 单击按钮

  5. 5

    如何使用 Selenium C# 单击按钮

  6. 6

    当文本更改为其他内容时,如何使用Selenium和Python单击按钮?

  7. 7

    使用 Selenium 和 Java 单击按钮时出现问题

  8. 8

    在 Python 中使用 Selenium 单击按钮时遇到问题

  9. 9

    当我尝试单击可扩展区域中的按钮时,出现OpenQA.Selenium.NoSuchElementException

  10. 10

    NoSuchElementException:消息:尝试通过 Selenium 和 Python 单击 VISA 按钮时无法定位元素

  11. 11

    ElementNotVisibleException:消息:尝试通过 Selenium 和 Python 单击按钮时元素不可交互错误

  12. 12

    使用Selenium单击按钮Python

  13. 13

    尝试单击导航按钮时,Espresso AmbiguousViewMatcherException

  14. 14

    单击按钮时尝试创建imageView

  15. 15

    如何使用Selenium单击网页上的打印按钮

  16. 16

    使用Selenium,如何根据相关标签单击单选按钮

  17. 17

    如何使用Selenium和Python 2.7单击表单中的按钮?

  18. 18

    如何使用Selenium通过文本或值单击按钮?

  19. 19

    如何单击使用<span>标记为Selenium Webdriver创建的按钮

  20. 20

    如何使用Selenium和Python在iframe中单击按钮

  21. 21

    如何使用Python + Selenium在警报中单击“确定”按钮

  22. 22

    如何使用Selenium和Python单击“搜索”按钮?

  23. 23

    如何使用Selenium在Python上单击iframe按钮?

  24. 24

    如何使用python,selenium单击框架内的按钮?

  25. 25

    使用Selenium,如何根据相关标签单击单选按钮

  26. 26

    如何单击使用<span>标记为Selenium Webdriver创建的按钮

  27. 27

    如何使用Selenium和Python单击确认按钮?

  28. 28

    如何使用 selenium (Python) 单击 Alertify 对话框按钮

  29. 29

    如何使用 python 和 selenium 单击此按钮

热门标签

归档