Clear Filters
Clear Filters

Is it possible to use the Selenium library, webdriver.Chrome in MATLAB?

32 views (last 30 days)
I have a code in python and am passing the application to MATLAB. Only the code is using the webdriver library to grab the information from the site.
# Open site
browser = webdriver.Chrome ()
browser.get ('http://icgem.gfz-potsdam.de/ICGEM/Service.html')
        
# Model Directory
model_dir = Select (browser.find_element_by_id ('model_directory'))
model_dir.select_by_visible_text (dire)
How can I solve it?
  1 Comment
Amit Madahar
Amit Madahar on 23 Aug 2019
Hi Lucas,
Did you manage to use Selium libraries in Matlab to run headless chrome? I am trying to resolve a similar issue.
Thanks
Amit

Sign in to comment.

Answers (1)

Daniel
Daniel on 24 Mar 2023
When I wanted to do something like this recently, I was able to run the Python file containing the Selenium calls from MATLAB. Relevant commands:
pyrun runs a single command in the Python environment.
pyrunfile executes a .py file.
Both of these commands can pass outputs back to MATLAB.
To point MATLAB to the correct Python interpreter, you use pyenv.
Here are the commands I used to import temperature data from a website for analysis:
The first time I used Python, I ran
pyenv(Version="C:\Users\<username>\AppData\Local\Programs\Python\Python310\python.exe")
to link MATLAB to my Python 3.10 installation. That got stored in MATLAB's settings, so I haven't needed to run that since.
To pull weather, I run
[daysText, tempsText] = pyrunfile("crawlWeather.py",["daysText","tempsText"],year=year,month=month);
"crawlWeather.py", obviously, is the name of the Python script, which assumes that "year" and "month" exist, and pulls weather data accordingly.
"daysText" and "tempsText" are the names of the variables which the script generates, and which I want to import into MATLAB for further analysis. So the argument ["daysText","tempsText"] asks pyrunfile to return those two variables, and I collect them as the return arguments.
"year=year" sets the Python variable "year" to the contents of the MATLAB variable "year".

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!