i'm doing a project
py
i=0
while i<=3:
i=i 1
try:
a=driver.find_element(By.XPATH,'//*[@id="search"]/div[1]/div[1]/div/span[1]/div[1]/div[ İ value ]/div/div/div/div/div[2]/div[1]/h2/a/span').text
except:
a=driver.find_element(By.XPATH,'//*[@id="search"]/div[1]/div[1]/div/span[1]/div[1]/div[ İ value ]/div/div/div/div/div[3]/div[1]/h2/a/span').text
print(a)
i want to do it this way, but i couldn't write the i value in the places where it should be written i'm doing a project
i=0
while i<=3:
i=i 1
try:
c=str(i)
veri=(f'//*[@id="search"]/div[1]/div[1]/div/span[1]/div[1]/div[{c}]/div/div/div/div/div[2]/div[1]/h2/a/span')
a=driver.find_element(By.XPATH,veri).text
except:
c=str(i)
veri=(f'//*[@id="search"]/div[1]/div[1]/div/span[1]/div[1]/div[{c}]/div/div/div/div/div[3]/div[1]/h2/a/span')
a=driver.find_element(By.XPATH,veri).text
print(a)
i tried this bandy, but it didn't happen, i know how to do it, can anyone with knowledge about it help
CodePudding user response:
use f string
a=driver.find_element(By.XPATH,f'//[@id="search"]/div[1]/div[1]/div/span[1]/div[1]/div[{i}]/div/div/div/div/div[2]/div[1]/h2/a/span').text
or old style string formatting
a=driver.find_element(By.XPATH,'//[@id="search"]/div[1]/div[1]/div/span[1]/div[1]/div[%d]/div/div/div/div/div[2]/div[1]/h2/a/span' % i).text