如果启用了检查按钮,则无法执行else语句代码 [英] Cannot execute if else statement code when checking button is enabled

查看:113
本文介绍了如果启用了检查按钮,则无法执行else语句代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我单击申请工作"后,我正在尝试检查container.com上的按钮,但是我的代码似乎无法正常工作. 首先检查是否启用了继续按钮,然后它将关闭页面,切换到主窗口并申请下一个作业.如果在if语句中使用if else来检查是否还有另一个继续按钮,它将关闭页面并切换到主窗口;如果不单击应用"按钮来完成并关闭页面,然后切换到主窗口.

I'm trying to check the button on indeed.com after you click apply job, but my code doesn't seem to work. The first if to check if the continue button is enabled if not, then it will close the page, switch to the main window and apply for the next job. The if else inside the if statement to check if there another continue button, it will close the page and switch to main window if not click on apply button to finish and close the page then switch to main window.

对不起,我还不能发布图片,所以我必须链接它们.

Sorry, I cannot post pictures yet so I have to link them.

这是您点击应聘职位后的图片 https://imgur.com/FzITw8q

Here's the picture after you hit apply job https://imgur.com/FzITw8q

这是图片,如果还有另一个继续按钮 https://imgur.com/iJMFqp8

Here's the picture if there another continue button https://imgur.com/iJMFqp8

如果没有继续按钮,仅应用按钮,则为以下图片 https://imgur.com/62KMUwY

Here's the picture if there's no continue button and only apply button https://imgur.com/62KMUwY

最后一个 https://imgur.com/ls4mwEi

# Click on continue button if there any             
if WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.XPATH,'//*[@id="form-action-continue"]'))).is_enabled():
    WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.XPATH,'//*[@id="form-action-continue"]'))).click()
    if WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.XPATH,'//*[@id="form-action-continue"]'))).is_enabled():
        self.driver.close()
        self.driver.switch_to.window(main) 
    else:
        WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.XPATH,'//*[@id="form-action-submit"]'))).click()
        self.driver.close()
        self.driver.switch_to.window(main) 
#If no button close the window and switch to main window
else: 
    self.driver.close()
    self.driver.switch_to.window(main)

我也尝试过is_displayed(),但是它根本不起作用.

I also tried is_displayed() but it doesn't work at all.

推荐答案

首先,我想知道您如何在WebDriverWait上调用isEnabled().这将只等待一个元素,直到找到它,并且不会返回其WebElement.因此,在第1、2和3行中启用了Apply时,将引发错误. 首先将该元素分配给一个变量,然后在WebDriverWait中调用该变量.找到/等待元素直到被WebDriverWait找到为止,请使用click或启用方法,该方法使用变量而不是WebDriverWait.

First, I am wondering how you are calling isEnabled() on WebDriverWait. This will just wait for an element until it is located and won't return its WebElement. Hence, when you apply is enabled in line 1, 2 and 3, it throws an error. First assign that element to one variable, and call that variable in WebDriverWait. Once element is located/ waited until element located by WebDriverWait, use click or is enabled methods using variable instead of WebDriverWait.

这篇关于如果启用了检查按钮,则无法执行else语句代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆