Ria*_*ani 6 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\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)
Run Code Online (Sandbox Code Playgroud)
我的代码片段是:
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 Code Online (Sandbox Code Playgroud)
方案是用户单击运行按钮并启动进程.当该过程完成时,将显示"无数据显示".我想等到这个文本显示然后我知道该过程已经完成.在我使用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"))
Run Code Online (Sandbox Code Playgroud)
错误显示:TypeError:init()正好接受3个参数(给定4个)
等待文本出现的正确语法是什么?谢谢,里亚兹
Selector 应该作为tuple传递,而不是作为两个单独的参数传递:
(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"))
Run Code Online (Sandbox Code Playgroud)
和
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"))
Run Code Online (Sandbox Code Playgroud)
您使用的语法EC.text_to_be_present_in_element("No data to display"))是错误的.
语法是:
class selenium.webdriver.support.expected_conditions.text_to_be_present_in_element(locator, text_)
Run Code Online (Sandbox Code Playgroud)
期望检查给定文本是否存在于指定元素中.定位器,文本
因此,很明显,您的代码中缺少定位器,其中要检查的文本.括号也是你面临的问题(在第二次编辑中).
使用如下(添加具有正确括号的定位器):
EC.text_to_be_present_in_element((By.ID, "operations_monitoring_tab_current_ct_fields_no_data"), "No data to display")
Run Code Online (Sandbox Code Playgroud)
注意:By.id只是一个例子.您可以使用任何定位器来识别selenium支持的元素
| 归档时间: |
|
| 查看次数: |
15945 次 |
| 最近记录: |