Checking if an element exists with Python Selenium

For a): from selenium.common.exceptions import NoSuchElementException def check_exists_by_xpath(xpath): try: webdriver.find_element_by_xpath(xpath) except NoSuchElementException: return False return True For b): Moreover, you can take the XPath expression as a standard throughout all your scripts and create functions as above mentions for universal use. I recommend to use CSS selectors. I recommend not to mix/use “by id”, “by … Read more

In PyQt, what is the best way to share data between the main window and a thread

Widgets are not thread safe, see Threads and QObjects: Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. And see more definitions here: Reentrancy and Thread-Safety You should only use widgets in the main thread, and use signal and … Read more

Encrypt and decrypt using PyCrypto AES-256

Here is my implementation, and it works for me with some fixes. It enhances the alignment of the key and secret phrase with 32 bytes and IV to 16 bytes: import base64 import hashlib from Crypto import Random from Crypto.Cipher import AES class AESCipher(object): def __init__(self, key): self.bs = AES.block_size self.key = hashlib.sha256(key.encode()).digest() def encrypt(self, … Read more

Find difference between two data frames

By using drop_duplicates pd.concat([df1,df2]).drop_duplicates(keep=False) Update : The above method only works for those data frames that don’t already have duplicates themselves. For example: df1=pd.DataFrame({‘A’:[1,2,3,3],’B’:[2,3,4,4]}) df2=pd.DataFrame({‘A’:[1],’B’:[2]}) It will output like below , which is wrong Wrong Output : pd.concat([df1, df2]).drop_duplicates(keep=False) Out[655]: A B 1 2 3 Correct Output Out[656]: A B 1 2 3 2 3 … Read more