Selenium Python等待元素中出现文本错误显示接受3个参数2
我正在使用WebdriverWait等待一些文本出现在网页上的元素中。我将Selenium与Python一起使用。我的语法不正确。 我得到一个错误: TypeError:init()正好接受3个参数(给定2个): 错误跟踪:Selenium Python等待元素中出现文本错误显示接受3个参数2,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我正在使用WebdriverWait等待一些文本出现在网页上的元素中。我将Selenium与Python一起使用。我的语法不正确。 我得到一个错误: TypeError:init()正好接受3个参数(给定2个): 错误跟踪: Traceback (most recent call last): File "E:\test_runners 2 edit project\selenium_regression_test_5_1_1\Regression_TestCase\RegressionPr
Traceback (most recent call last):
File "E:\test_runners 2 edit project\selenium_regression_test_5_1_1\Regression_TestCase\RegressionProjectEdit_TestCase.py", line 2714, in test_000057_run_clean_and_match_process
process_lists_page.wait_for_run_process_to_finish()
File "E:\test_runners 2 edit project\selenium_regression_test_5_1_1\Pages\operations.py", line 334, in wait_for_run_process_to_finish
EC.text_to_be_present_in_element("No data to display"))
TypeError: __init__() takes exactly 3 arguments (2 given)
我的代码片段是:
def wait_for_run_process_to_finish(self): # When the process is running use WebdriverWait to check until the process has finished. No data to display is shown when process has completed.
try:
WebDriverWait(self.driver, 900).until(
EC.text_to_be_present_in_element("No data to display"))
no_data_to_display_element = self.get_element(By.ID, 'operations_monitoring_tab_current_ct_fields_no_data')
print "no_data_to_display_element ="
print no_data_to_display_element.text
if no_data_to_display_element.text == "No data to display":
return True
except NoSuchElementException, e:
print "Element not found "
print e
self.save_screenshot("wait_for_run_process_to_finish")
场景是用户单击run按钮并启动流程。
流程完成后,将显示文本“无需显示的数据”。
我想等到这个文本显示出来,然后我知道这个过程已经完成。
在我使用time.sleep(900)之前,这并不好,因为它会显式地等待整整15分钟。这个过程可能在8分钟内完成,有时是12分钟
我也尝试过:
WebDriverWait(self.driver, 900).until(
EC.text_to_be_present_in_element(By.ID, 'operations_monitoring_tab_current_ct_fields_no_data', "No data to display"))
错误显示:TypeError:init()正好接受3个参数(给定4个)
等待文本出现的正确语法是什么?
谢谢,Riaz选择器应作为元组传递,但不能作为两个单独的参数传递:
(By.TYPE,VALUE,TEXT)
-->((By.TYPE,VALUE,TEXT)
所以试着去替换
WebDriverWait(self.driver, 900).until(
EC.text_to_be_present_in_element(By.ID, 'operations_monitoring_tab_current_ct_fields_no_data', "No data to display"))
与
用于
EC.text\u to\u present\u in\u元素(“无数据显示”)
的语法错误
语法是:
class selenium.webdriver.support.expected_conditions.text_to_be_present_in_element(locator, text_)
检查给定文本是否存在于
指定的元素。文本定位器
因此,很明显,要检查文本的代码中缺少定位器。插入括号也是您面临的问题(在第二次编辑中)
使用以下命令(添加带正确括号的定位器):
注意:By.id只是一个例子。您可以使用任何定位器来标识selenium支持的元素是否包括使用
(by.CSS,“selector”)
?找不到相关文档:(请在元素中尝试EC.text_to_be_present_((By.CSS_SELECTOR,“SELECTOR”),“text to check”)。文档在此处
class selenium.webdriver.support.expected_conditions.text_to_be_present_in_element(locator, text_)
EC.text_to_be_present_in_element((By.ID, "operations_monitoring_tab_current_ct_fields_no_data"), "No data to display")