1

I have a project named testrequest and I am working on a file named test_function_pack.py. The working code within the said file is below:

service = Service(r'C:\user\Dev\Selenium\testrequest\drivers\chromedriver.exe')

I wish to try accessing the chromedriver.exe file using .. or . dots and by my understanding, the distance of the two file is two directories upward. I tested using the below code

import os
os.chdir('..')
service = Service(r'../../drivers/chromedriver.exe')

But the code above does not work, am I missing anything here? Any help is appreciated.

Here is the folder by the way:

enter image description here

KiritoLyn
  • 626
  • 1
  • 10
  • 26

1 Answers1

1

I guess something like this should work.

import os
stepups = 2
a = '/'.join(os.path.dirname(__file__).split('\\')[:stepups]) + '/drivers/chromedriver.exe'
print(a)

Do your own work regarding the step-ups you require, and change that accordingly.

Ankan Das
  • 268
  • 1
  • 2
  • 11