0

I want to upload a .apk file to Kaspersky's online scanner by using selenium and Python. However, the file is interpreted as a URL when I use selenium's send_keys() method.

The relevant HTML looks like this:

    <div class="container">
      <div class="div-field-home">
        <div class="div-hero-scanner-wrapper">
<!-- ======= -->

          <div class="acenter pdv-1x" id="drop-area">
            <form action="" id="SendForm">
              <div class="d-inline">
                  <div class="tags-inline amiddle file-load-group">
                      <input id="txt-input-01" type="text" class="small" placeholder="Drag-and-drop a file or paste a link here" maxlength="2000" txtvalue="">
                      <a href="#" class="d-inline bt-attach bt-attach-file"><img src="/resources/img/attach.png" class="w-100" alt=""><img src="/resources/img/attach_inactive.png" class="w-100" alt=""></a>
                      <a href="#" class="btn upper small bt-attach-res bt-attach-file">Attach file</a>
                      <a href="#" class="btn upper clr-ff bg-02 small bt-check bt-disable" analytics-event="StartScan.Click">Scan</a>
                  </div>

Code:

kaspersky_base_URL = "https://virusdesk.kaspersky.com/#"

driver = webdriver.Firefox()
driver.get(kaspersky_base_URL)
file = "/home/user/filepath"

driver.implicitly_wait(30)

input = driver.find_element_by_id("txt-input-01")
input.send_keys(file)

driver.implicitly_wait(60)

links = driver.find_elements_by_xpath('//a[contains(@href, "#")]')
for elem in links:
    if 'SCAN' in elem.text:
        elem.click()

I have also tried to change the input type=text to type=file. It is changed, but the same error keeps occurring. I think that the problem might be that one has to click on the file attack link for the text to be interpreted as a file. But not completely sure.

Any help would be appreciated!

Ina
  • 1
  • 1

1 Answers1

0

Seems you were close enough. To upload a .apk file to Kaspersky's online scanner using Selenium and you need to induce WebDriverWait for the element_to_be_clickable() while:

  • Dragging and Dropping the apk file from your local system or
  • Providing the link of the apk url.

Following the second method of providing the link of the apk url, you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://virusdesk.kaspersky.com/#')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#txt-input-01"))).send_keys("https://drive.google.com/file/d/1ZspxTOnQpqcuvI0rDAkBsB_Y-gRzIEaq/view/GranthamBuild14022020.apk")
    
  • Using XPATH:

    driver.get('https://virusdesk.kaspersky.com/#')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='txt-input-01']"))).send_keys("https://drive.google.com/file/d/1ZspxTOnQpqcuvI0rDAkBsB_Y-gRzIEaq/view/GranthamBuild14022020.apk")
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

apk_scan

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for your answer. However, this solution only scans the URL, and not the file itself. So if I give it the url to a malicious apk it says the url is all good - if I upload the file (manually) it says it conatins threats. – Ina Feb 19 '20 at 11:49
  • @Ina This [Selenium](https://stackoverflow.com/questions/54459701/what-is-selenium-and-what-is-webdriver/54482491#54482491) is based solution was to help you populate the `` tag with a valid character sequence, irrespective of the validation performed by the website, which is out of scope for this question. – undetected Selenium Feb 19 '20 at 12:00