相关疑难解决方法(0)

检查Selenium Java中是否可以单击元素

我是新手Selenium,需要检查元素是否可点击Selenium Java,因为element.click()传递linklabel.

我尝试使用下面的代码,但没有工作:

WebDriverWait wait = new WebDriverWait(Scenario1Test.driver, 10);

if(wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//div[@id='brandSlider']/div[1]/div/div/div/img)[50]")))==null)
Run Code Online (Sandbox Code Playgroud)

需要帮助.

java selenium automation selenium-webdriver

12
推荐指数
3
解决办法
9万
查看次数

Python-Selenium 查找不可点击的可点击元素

我用来python-selenium运行自动化测试。在复杂的非公共环境中运行这些测试时,我发现了一些我将标记为 selenium 中的错误的东西。

基本上我想做的是在 DOM 中找到一些元素,当它变得可点击时,然后点击它。代码如下:

....
what = (By.XPATH, '//button/span[contains(text(), "Load")]')
element = WebDriverWait(bspdriver.webdriver, 60).\
                until(EC.element_to_be_clickable(what))
element.click()
....
Run Code Online (Sandbox Code Playgroud)

但是,该click方法几乎立即失败,并显示以下错误消息:

ElementClickInterceptedException: Message: Element <button class="ivu-btn ivu-btn-primary ivu-btn-long ivu-btn-small" type="button"> is not clickable at point (1193.3332901000977,522) because another element <div class="ivu-modal-wrap vertical-center-modal circuit-loading-modal"> obscures it
Run Code Online (Sandbox Code Playgroud)

我虽然正在等待该元素可点击!我以为这EC.element_to_be_clickable就是这个意思。但事实并非如此。这是硒中的错误吗?

解决方法是使用以下代码:

    mustend = time.time() + 60
    while time.time() < mustend:
        try:
            WebDriverWait(bspdriver.webdriver, 60).\
                until(EC.element_to_be_clickable(what)).click()
            break
        except (TimeoutException, NoSuchElementException,
                StaleElementReferenceException,
                ElementClickInterceptedException) as e:
            time.sleep(1.0)
Run Code Online (Sandbox Code Playgroud)

这对我来说看起来不太好。有没有办法改进代码?硒有缺陷吗?如果是的话我可以举报...

使用过的包:

  • 硒 3.8.0 …

python selenium

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

标签 统计

selenium ×2

automation ×1

java ×1

python ×1

selenium-webdriver ×1