Xin các bác cứu em về connect Dapp trên metamask button bằng selenium

laophatgia76

Junior
Joined
Apr 9, 2023
Messages
38
Reactions
7
MR
0.610
chào các bác hiện tại e đang code selenium nhưng ko bấm vào xpath của thằng button next trên metamask popup được, lỗi ko tìm thấy phần tử. Mặc dù e f12 và dán xpath vào thì tìm thấy element.


1739764354491.png
 
đây là code của e
Click vào nút "Kết nối" trên MetaMask
windows = driver.window_handles
print(windows) # Kiểm tra thứ tự của cửa sổ
# Chuyển sang cửa sổ popup
driver.switch_to.window(windows[1])
time.sleep(3)
# Kiểm tra kỹ XPath của nút 'Next'
try:
connect_button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//button[@data-testid='page-container-footer-next']")))
connect_button.click()
except Exception as e:
print(f"Không tìm thấy phần tử 'Next': {e}")
# Quay lại cửa sổ chính
driver.switch_to.window(windows[0])
 

leenguyen69

Senior
Joined
Sep 5, 2014
Messages
642
Solutions
2
Reactions
508
MR
3.977
driver.switch_to.window(windows[1])
Thay bằng code trên mạng này thử xem được không, chắc chưa chuyển qua đúng popup tại mình thấy 1 số code nó lấy index 2 , 1 số lại 1 :
Python:
for handle in driver.window_handles:
        driver.switch_to.window(handle)
        time.sleep(0.1)
        if 'MetaMask' in driver.title:
            break
 
Python:
windows = driver.window_handles
print(windows) # Kiểm tra thứ tự của cửa sổ
# Chuyển sang cửa sổ popup
for handle in driver.window_handles:
        driver.switch_to.window(handle)
        time.sleep(0.1)
        if 'MetaMask' in driver.title:
            break
time.sleep(3)
# Kiểm tra kỹ XPath của nút 'Next'
try:
connect_button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//button[@data-testid='page-container-footer-next']")))
connect_button.click()
except Exception as e:
print(f"Không tìm thấy phần tử 'Next': {e}")
# Quay lại cửa sổ chính
driver.switch_to.window(windows[0])
 

Announcements

Today's birthdays

Forum statistics

Threads
428,246
Messages
7,229,614
Members
180,363
Latest member
shu171201

Most discussed of week

Most discussed of week

Back
Top Bottom