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

Rajath Rao
  • 873
  • 7
  • 23
KiritoLyn
  • 495
  • 1
  • 7
  • 18
  • https://stackoverflow.com/a/65333932/9928905 You can use this piece of code by that you can automate the process of configuring the chromedriver to the latest version – Rajath Rao Jan 04 '22 at 11:11

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
  • 238
  • 1
  • 2
  • 8