相关疑难解决方法(0)

复合类名称不允许错误Webdriver

我收到以下错误:

"不允许使用复合类名称"

尝试访问web元素时,元素的类名称之间有空格.Web元素的页面源如下所示.

driver.findElement(By.className("alert alert-success"));
Run Code Online (Sandbox Code Playgroud)

<div class="alert alert-success" alert-dismissable"="" id="58417" style="display: none;">
   <button type="button" class="close hide-panel close-icon-58417" data-dismiss="alert" aria-hidden="true" style="display: inline-block;">×</button><span id="caret-58417" class="notification-caret caret-58417"></span>
   <div class="hide-panel close-icon-58417" id="58417" style="display: block;">
      <span class="glyphicon glyphicon-ok-sign"></span><strong>Success</strong> KeyLinks Updated Successfully
      <div class="notification-panel-body panel-body-58417">REST Invocation Success</div>
   </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我试图通过CSS路径找到元素,如下所示.但是这个元素无法搜索到.

driver.findElement(By.cssSelector(".alert alert-success"));
Run Code Online (Sandbox Code Playgroud)

这是链接中给出的解决方法,但仍然没有成功.非常感谢您的帮助.

selenium-webdriver

26
推荐指数
3
解决办法
7万
查看次数

不允许使用Selenium Compound类名

我有下面的代码点击一个元素来弹出一个屏幕并复制其中的文本

el1 = driver.find_element_by_id("keyDev-A")
el1.click()
el2 = driver.find_element_by_class_name("content")
print(el2.text)
Run Code Online (Sandbox Code Playgroud)

但是,当我试图selenium单击该弹出窗口中的按钮时

el3 = driver.find_element(By.CLASS_NAME, "action-btn cancel alert-display")
el3.click()
Run Code Online (Sandbox Code Playgroud)

它会产生一条错误消息: invalid selector: Compound class names not permitted

这是我试图selenium点击的HTML .该Close按钮.

<div class="nav">
    <span class="action-btn confirm prompt-display">Confirm</span>
    <span class="action-btn cancel prompt-display">Cancel</span>
    <span class="action-btn cancel alert-display">Close</span>
</div>
Run Code Online (Sandbox Code Playgroud)

我应该怎么写el3才能点击关闭按钮?

python selenium

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

WebDriver中不支持复合类名称错误

我有一种方法来计算元素的数量divs并返回它们的数量.

 public int getNumberOfOpenBets() {

     openBetsSlip = driver.findElement(By.id("form_open_bets"));
     openBets = openBetsSlip.findElements(By.className(" cashout_noCash"));
     return openBets.size();
 }
Run Code Online (Sandbox Code Playgroud)

这是页面源

<form id="form_open_bets" method="post" name="form_open_bets">
    <input type="hidden" value="" name="action">
    <input type="hidden" value="" name="bet_id">
    <input type="hidden" value="" name="cashout_price">
    <input id="target_page" type="hidden" value="" name="target_page">
    <div id="By.id" class="slipWrapper ">
        <div id="openBets_header"></div>
        <div id="cashout_1626" class=" cashout_noCash">
            <div id="cashout_1625" class=" cashout_noCash">
                <div id="cashout_1615" class=" cashout_noCash">
                    <div id="cashout_1614" class=" cashout_noCash">
                        <div id="cashout_1613" class=" cashout_noCash">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

WebDriver抛出以下错误:不支持复合类名.考虑搜索一个类名并过滤结果或使用CSS选择器.

org.openqa.selenium.InvalidSelectorException: Compound class names are not supported. …
Run Code Online (Sandbox Code Playgroud)

css java selenium webdriver selenium-webdriver

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

使用Selenium和Python,如何检查按钮是否仍然可点击?

所以我正在使用Selenium和Python进行一些网络抓取,我遇到了问题.我点击"下一步"按钮移动到某个网站的下一页,但是当我到达最后一页时,我需要停止点击它.现在,我这样做的想法就是在try/except语句中使用some_element.click()并等到它给我一个错误,而按钮不再可点击.看来,.click()不会发出任何类型的信号,当按钮无法点击并且不发出任何真或假信号时,它不会抛出错误.

我尝试使用的代码段:

while True:
    try:
       button = driver.find_element_by_class_name('Next_button')
       button.click()
    except:
       break
Run Code Online (Sandbox Code Playgroud)

还有其他方法吗?谢谢和欢呼.

python selenium web-scraping

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

选择器无效:使用Webdriver和Python的find_element_by_class_name不允许使用复合类名

我正在尝试通过webWhatsapp从聊天中打印我的消息之一。

我可以通过“控制台”选项卡中的Javascript完成此操作

recived_msg = document.getElementsByClassName('XELVh selectable-text invisible-space copyable-text') // returns an array of the chat
recived_msg[5].innerText // shows me the 4th message content
Run Code Online (Sandbox Code Playgroud)

问题是我试图在python上做同样的事情,但对我不起作用。

这是我尝试过的:

from selenium import webdriver
recived_msg = driver.find_element_by_class_name('XELVh selectable-text invisible-space copyable-text')
final = recived_msg[5].innerText #doesnt work for some reason
Run Code Online (Sandbox Code Playgroud)

我遇到的错误是:消息:无效的选择器:不允许使用复合类名

我对javascript有点陌生,所以很抱歉造成误会,并感谢您的帮助!:)

xpath webdriver css-selectors python-3.x selenium-webdriver

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