ui自动化 deriver.get(url) 报错AttributeError: 'MainPage' object has no attribute 'get'
时间: 2024-05-24 21:08:44 浏览: 30
这个报错是因为你在一个MainPage对象上调用了get方法,但是MainPage类中没有定义get方法。一般情况下,我们使用Selenium库进行UI自动化测试时,需要先创建一个webdriver对象,然后使用这个对象对网页进行操作。因此,在使用get方法之前,你需要先创建一个webdriver对象,并将它传入到MainPage类中。
举个例子,如果你使用Chrome浏览器,可以按照以下方式创建webdriver对象:
```
from selenium import webdriver
driver = webdriver.Chrome()
```
然后,在创建MainPage对象时,将driver对象传入:
```
from pages.main_page import MainPage
main_page = MainPage(driver)
```
这样,在MainPage类中就可以使用driver的方法了,比如:
```
def open_login_page(self):
self.driver.get("https://www.example.com/login")
```
相关问题
如何用python 验证ecies 256 和384 加密解密的正确性
要验证 ECIES 256 和 384 的加密解密正确性,可以使用 Python 中的 cryptography 库。下面是一个示例代码,展示了如何使用该库进行验证。
首先,需要安装 cryptography 库。可以使用以下命令进行安装:
```
pip install cryptography
```
接下来,可以使用以下代码进行 ECIES 256 的加密和解密:
```python
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
# Generate a new private key
private_key = ec.generate_private_key(ec.SECP256R1())
# Get the corresponding public key
public_key = private_key.public_key()
# Serialize the public key
serialized_public_key = public_key.public_bytes(
encoding=serialization.Encoding.X962,
format=serialization.PublicFormat.UncompressedPoint
)
# Generate a shared secret using the public key
shared_secret = private_key.exchange(ec.ECDH(), public_key)
# Derive a symmetric key using HKDF
key_deriver = HKDF(
algorithm=hashes.SHA256(),
length=32,
salt=None,
info=b'ecies symmetric key'
)
symmetric_key = key_deriver.derive(shared_secret)
# Generate a random nonce
nonce = AESGCM.generate_nonce()
# Encrypt the message using AES-GCM
plaintext = b'This is a secret message.'
cipher = AESGCM(symmetric_key)
ciphertext = cipher.encrypt(nonce, plaintext, None)
# Decrypt the message using AES-GCM
cipher = AESGCM(symmetric_key)
decrypted_plaintext = cipher.decrypt(nonce, ciphertext, None)
# Verify that the decrypted message is the same as the original plaintext
assert decrypted_plaintext == plaintext
```
类似地,可以使用以下代码进行 ECIES 384 的加密和解密:
```python
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
# Generate a new private key
private_key = ec.generate_private_key(ec.SECP384R1())
# Get the corresponding public key
public_key = private_key.public_key()
# Serialize the public key
serialized_public_key = public_key.public_bytes(
encoding=serialization.Encoding.X962,
format=serialization.PublicFormat.UncompressedPoint
)
# Generate a shared secret using the public key
shared_secret = private_key.exchange(ec.ECDH(), public_key)
# Derive a symmetric key using HKDF
key_deriver = HKDF(
algorithm=hashes.SHA384(),
length=48,
salt=None,
info=b'ecies symmetric key'
)
symmetric_key = key_deriver.derive(shared_secret)
# Generate a random nonce
nonce = AESGCM.generate_nonce()
# Encrypt the message using AES-GCM
plaintext = b'This is a secret message.'
cipher = AESGCM(symmetric_key)
ciphertext = cipher.encrypt(nonce, plaintext, None)
# Decrypt the message using AES-GCM
cipher = AESGCM(symmetric_key)
decrypted_plaintext = cipher.decrypt(nonce, ciphertext, None)
# Verify that the decrypted message is the same as the original plaintext
assert decrypted_plaintext == plaintext
```
在这里,我们使用了 AES-GCM 来加密和解密消息,使用 HKDF 来从共享密钥派生对称密钥。如果加密和解密都成功,那么最后的 assert 语句应该不会引发异常。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)