1

I have the following URL which I want to post the form:

https://cluspro.bu.edu/home.php

This script does the job (thanks to DPH):

library(RSelenium)

# Follow  instruction here
# https://rpubs.com/grahamplace/rseleniumonmac
# Step 1: cd /path_to_r_code/
# Step 2: ./geckodriver     #downloadable here: https://github.com/mozilla/geckodriver/releases/tag/v0.30.0
# Step 3: java -jar selenium-server-standalone.jar -port 5556
# Step 4: run this script

webpage <- 'https://cluspro.bu.edu/home.php'
my_jobname <- "test"
receptor_pdb <- "/path/to/my_file/2fyl.pdb"
ligand_pdb <- "/path/to/my_file/144_from_2yrq.pdb" # tried with double slash but don't work
browser <- remoteDriver(port = 5556)
browser$open()
browser$navigate(webpage)

# This works
clk <- browser$findElement(using = "link text", "Use the server without the benefits of your own account")
clk$clickElement()

# This works
jbn <- browser$findElement(using = "name", "jobname")
jbn$sendKeysToElement(list(my_jobname))

# This works
svr <- browser$findElement(using = "name", "server")
svr$sendKeysToElement(list("gpu"))

# This doesn't work
receptor <- browser$findElement(using = "id", "showrecfile")
receptor$clickElement()
receptor$sendKeysToElement(list(receptor_pdb))

# # This doesn't work as well
# ligand <- browser$findElement(using = "id", "showligfile")
# ligand$sendKeysToElement(list(ligand_pdb))
# 
# This works
agree <- browser$findElement(using = "name", "noncommercial")
agree$clickElement()
# 
# This works
# dock <- browser$findElement(using = "name", "action")
# dock$clickElement()

Except on the page where it ask for browser upload to receptor:

enter image description here

The corresponding HTML is this:

  <div>
    <span id="showrecpdb" class="link">Use PDB ID</span><span id="showrecfile" class="link">Upload PDB</span>
  </div>

This part of the code above:

receptor <- browser$findElement(using = "id", "showrecfile")
receptor$clickElement()
receptor$sendKeysToElement(list(receptor_pdb))

only activated the browser button like below but no file uploaded or selected.

enter image description here

If it works, it'll look something like this:

enter image description here

How can I enable it?

I'm using MacOS.X

The PDB file can be downloaded here (receptor) and here (ligand).

2 Answers 2

2
+150

Is this what you are after:

# This for upload 1 link
receptor <- browser$findElement(using = "id", "showrecfile")
receptor$clickElement()

# This is the upload 1 file element
rec <- browser$findElement(using = "id", "rec")
rec$sendKeysToElement(list(receptor_pdb))

# This for upload 2
ligand <- browser$findElement(using = "id", "showligfile")
ligand$clickElement()

#This is the upload 2 file element
lig <- browser$findElement(using = "id", "lig")
lig$sendKeysToElement(list(ligand_pdb))
Sign up to request clarification or add additional context in comments.

2 Comments

upvote, though I did not test it (no dropbox), anyhow this should be the solution - no way arround clicking the button I guess!
@djmonki you saved my life!
2

The RSelenium package enables to remote control the comon web browsers from R. The following code opens a remote browser session in mozilla firefox(chrome should work as well) and works the login screen - with the correct usr and pw the next page will open. As I do not have access to the closed part I can not try nor debug my code after the login screen click so I just showed one upload:

library(RSelenium)
webpage <- 'https://cluspro.bu.edu/home.php'
# set up and start remote controlle browser
driver <- RSelenium::rsDriver(browser = 'firefox', port = 4818L)
remDr <- driver[['client']]
# navigate to the page
remDr$navigate(webpage)
# find elements by id and populate/click them
usr <- remDr$findElement(using = "id", "username")
usr$sendKeysToElement(list("your user name"))
psw <- remDr$findElement(using = "id", "password")
psw$sendKeysToElement(list("your password"))
clk <- remDr$findElement(using = "id", "submit")
clk$clickElement()
# next page will open (you already know how to fill out the textboxes so here goes one upload
upl <- remDr$findElement(using = "id", "showrecpdb")
# you need a path with these double backslashes
upl$sendKeysToElement(list("C:\\...\\...\\your_file.something"))
# session end
remDr$close()

6 Comments

DPH thanks. I'm almost there. Everything works except the uploading of the file part. Note that the web page has a dropodown browse file for receptor and ligand upload procedure. Please see my update in my OP.
@scamander have you tried to write de file path with double backslashes not an object... on win maschines it does not work with simple slash or backslash as far as I am aware? (I can not see the content of "ligand_pdb")
I tried double slash, but still won't work. I'm using MacOS.X.
I updated my post with the link where you can download the ligand_pdb file to test for uploading.
@scamander unfortunately I do not have any MAC PC also I do not have access to the closed area - I have tried the shown combination of function calls to make an upload from Win10pro PC to this public Website maxlaumeister.com/pagecrypt and it works
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.