Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

java - Problem with "element not reachable by keyboard" in Selenium Webdriver

I'm having a problem in Selenium Webdriver.

I need to upload a file for a site. Here is what I tried:

driver.findElement(By.cssSelector(".icon-upload-cloud"))
      .sendKeys(
          "C:"                    + File.separator +
          "Users"                 + File.separator +
          "Vinicius"              + File.separator +
          "OneDrive"              + File.separator +
          "Arquivos para códigos" + File.separator +
          "Logo empresa.png"
      );

The problem is the button to upload is returning the error: "element is not reachable by keyboard".

I can solve the problem with this:

new WebDriverWait(driver, 20)
    .until(
        ExpectedConditions.elementToBeClickable(
            By.cssSelector(".icon-upload-cloud")
        )
    )
    .click();

But then I don't know how to upload a file because Windows opens a file selection dialog box, and I can't use sendKeys().

question from:https://stackoverflow.com/questions/66052567/problem-with-element-not-reachable-by-keyboard-in-selenium-webdriver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

“element not reachable by keyboard”

Means exactly the same thing you cannot interact with that element using keyboard

I think you are interacting with a button element instead of 'input' element

if you want to upload using send_keys, you should be sending to element with input tag whos display property is not none, and is not disabled


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...