Search code examples
pythonseleniumpathdriverpathlib

Get a file that is in a folder that is a child of the parent directory with python


I have attempted this heavily but have found no way to do this, I think I am not understanding something.

Here is my tree of the .bat that runs it: https://i.sstatic.net/lrpvG.png

and here is my 'src' folder: https://i.sstatic.net/fLEc2.png

I am trying to be able to get the 'webdriver.exe' in the src file, from betav1.0.1.py.

So far I have gotten to this code:

import pathlib
from pathlib import Path
import os
path = pathlib.Path().absolute()
pathbase = os.path.basename(path)
import selenium
from selenium import webdriver

driver=webdriver.Chrome(os.path.basename(path).Path('\src\chromedriver.exe'))

but that returns the error

AttributeError: 'str' object has no attribute 'Path'

How would I do this?


Solution

  • I have found a solution to this. Instead, I used chromedriver-py (https://pypi.org/project/chromedriver-py/) to find the nearest webdriver.