第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何斷言復(fù)制到剪貼板的值是正確的?

如何斷言復(fù)制到剪貼板的值是正確的?

ITMISS 2021-11-12 15:02:14
在我的步驟中,我單擊了一個自動復(fù)制電子郵件地址的按鈕。我如何斷言該值是我期望的值?試圖找出一種將其粘貼到終端中的方法,以便我可以看到它在復(fù)制什么,但是如果有更有效的方法來做到這一點(diǎn),我很想知道。我嘗試根據(jù)其他一些建議導(dǎo)入 pyperclip,但沒有正確導(dǎo)入。這是點(diǎn)擊時復(fù)制值的按鈕,@step('I locate the email icon and click')def step_impl(context):    window_before = driver.window_handles[0]    context.current_element = context.wait.until(        EC.element_to_be_clickable(            (EMAIL_ICON)        )    )    scroll_to_webelement(context.driver, context.current_element)    time.sleep(3)    context.current_element.click()它會觸發(fā)您操作系統(tǒng)的默認(rèn)電子郵件以打開第二個窗口,以便將其關(guān)閉@step('I switch to the new window and close it')def step_impl(context):    context.wait.until(EC.number_of_windows_to_be(2))    context.driver.switch_to.window(context.driver.window_handles[-1])    context.driver.close()    context.driver.switch_to.window(context.driver.window_handles[0])我希望它給我復(fù)制的電子郵件,但我嘗試的每一步似乎都不起作用。
查看完整描述

2 回答

?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗 獲得超2個贊

下面是如何測試的示例。測試 HTML:


<!DOCTYPE html>

<html>

<body>

<input type="text" value="my@email.com" id="mm">

<button onclick="myFunction()">Copy text</button>

<script>

    function myFunction() {

        var copyText = document.getElementById("mm");

        copyText.select();

        copyText.setSelectionRange(0, 99999)

        document.execCommand("copy");

        window.open();

    }

</script>

</body>

</html>

測試代碼:


from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as ec


driver = webdriver.Chrome()

wait = WebDriverWait(driver, 5)

driver.get("file:///Users/***/Desktop/test.html")


# store input value

email = wait.until(ec.visibility_of_element_located((By.TAG_NAME, "input"))).get_attribute("value")

# click on button, that will copy value and open new tab

driver.find_element_by_tag_name("button").click()


# wait for the second window and switch to

wait.until(ec.number_of_windows_to_be(2))

driver.switch_to.window(driver.window_handles[-1])


# open google.com to check copied text

driver.get("https://www.google.com/")


google_q = driver.find_element_by_name("q")

# paste text to the google search input, SHIFT and INSERT keys for MacOS

google_q.send_keys(Keys.SHIFT, Keys.INSERT)

# assert copied value with stored

assert google_q.get_attribute("value") == email

# close current window and switch back to the first one

driver.close()

driver.switch_to.window(driver.window_handles[0])


查看完整回答
反對 回復(fù) 2021-11-12
?
精慕HU

TA貢獻(xiàn)1845條經(jīng)驗 獲得超8個贊

將剪貼板內(nèi)容存儲到一個變量中,并可以像往常一樣對其進(jìn)行斷言。請嘗試下面的代碼,讓我知道這是否有幫助。


Python 示例

import xerox

from selenium import webdriver


driver = webdriver.Chrome('/usr/local/bin/chromedriver')  

driver.implicitly_wait(15)


driver.get("https://clipboardjs.com/")

driver.find_element_by_xpath("//img[@alt='Copy to clipboard']").click() #clip board content copied here

i = xerox.paste() #clip board content stored into variable i

print i

print i == "npm install clipboard --save" #compare the clip board content against the expected value

driver.quit()

輸出:

npm install clipboard --save

True 


查看完整回答
反對 回復(fù) 2021-11-12
  • 2 回答
  • 0 關(guān)注
  • 199 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號