如果启用了检查按钮,则无法执行else语句代码

编程入门 行业动态 更新时间:2024-10-23 12:38:54
本文介绍了如果启用了检查按钮,则无法执行else语句代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm trying to check the button on indeed 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.

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

Here's the picture after you hit apply job imgur/FzITw8q

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

Here's the picture if there another continue button imgur/iJMFqp8

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

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

最后一个 imgur/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语句代码

本文发布于:2023-11-01 01:24:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   按钮   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!