Linked Questions

Popular Questions

I have such a problem when I have one XPATH everything works and there are no errors, but when I add a second XPATH it says that the first XPATH is wrong.

This way everything works fine:

from gettext import find
from msilib.schema import Class
import webbrowser
from selenium import webdriver
from import By
from selenium import webdriver
from import Service
from import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("...some website..")
class Code:
 def cookie(self):
         self.button = driver.find_element(By.XPATH, '//*[@id="pr_id_1_content"]/div/div/div[1]/div/div/div[4]/button') 
p = Code()

But when I append the second Xpath, it says the first one is wrong:

class Text:
 def promoCode(self):
          login_attempt = 0
          with open(r'C:\Users\hmiel.DESKTOP-825LQF4\Desktop\slownik1.txt', 'r') as f1, open(r'C:\Users\hmiel.DESKTOP-825LQF4\Desktop\slownik2.txt', 'r') as f2:
             wyrazy1 = f1.readlines()
             wyrazy2 = f2.readlines()

             lista_wyrazow = []
             i = 0
             j = 0

             while i == len(wyrazy1):
                   i += 1
             if j < len(wyrazy2):
                 j += 1

             for line in lista_wyrazow:
                  self.button_code = driver.find_element(By.ID, 'voucher-input')
                  self.button_code1 = driver.find_element(By.XPATH, '//*[@id="gatsby-focus-wrapper"]/main/div/div[1]/div/form/button')

                  login_attempt = login_attempt + 1
                  print(' Login attempt', login_attempt, ' with key/password : ', line)

d = Text()

How could I solve this issue? Any advice would be appreciated.

Related Questions