1
 img = "<img src='C:/Users/semnome/Desktop/21291010002.jpg'>"  //Path it's ok, it open if I try it manually on URL
 elm = driver.find_element_by_xpath(".//*[@id='content']")
 driver.execute_script("arguments[0].innerHTML = arguments[1];", elm, img);

it's a local execution (chrome in debugging mode)

works to create the tag, but Image is not showing in browser (just img icon). What I'm doing wrong?

diegooli
  • 123
  • 2
  • 11
  • 1
    I think you'd need: "file://" before the path... bit of an XSS issue there, though... might have cross-origin problems.. – pcalkins Dec 15 '21 at 00:18
  • 1
    for local file you have to use `file://` or `file:///` - like `file:///C:/Users/...`. But it may not work if load page from server because browser may block `file://` when it load data from server - all for security reason. – furas Dec 15 '21 at 02:17
  • @furas I try file:///C:/Users/ , so path blank spaces are not parsed correctly (path turns blue link before spaces). And results remained the same, images is not showing. it's a local execution (chrome in debugging mode) – diegooli Dec 15 '21 at 03:12
  • 2
    as I said - if you run it on page from internet then it may not work for security reason - because hacker could use it to steal file with your passwords or your naked images. And as I said: `file://` or `file:///` - I don't remeber which version it has to be. – furas Dec 15 '21 at 03:14
  • 1
    Please see https://stackoverflow.com/questions/4090712/why-cant-i-do-img-src-c-localfile-jpg – Nandan A Dec 15 '21 at 07:21

0 Answers0