1

Is there any way to read the text in an input without calling to get it from HTML? In the image, I want to get whatever value I can from the input, store it, then add a number to it, but it's not in the HTML(the input just refers to "quantity"

Not represented in HTML

Is there some way I could select the input box, copy the value, then interact with the value from there?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • This ans from stackoverflow may help. It is in Java,but try to implement in python. https://stackoverflow.com/questions/40624766/selenium-java-how-can-i-get-the-value#:~:text=You%20can%20get%20the%20value,.id(txtCatalogueNo))%3B%20System. – Swaroop Humane Dec 19 '21 at 19:29
  • Won't help unfortunately. The input has no value for the input. It's kept in the data-bind as some kind of variable, "quantity" which is also represented in other rows. Not sure how I would be able to even read it from HTML. From what I can tell, it's from knockout.js, which is intentionally making it hard to scrape it just from HTML. – Clockknight Dec 21 '21 at 03:15

2 Answers2

0

To print the text i.e. 1 you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.validation-message-container > input[data-bind*='isForwardFreightSeller']"))).get_attribute("value"))
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='validation-message-container']/input[contains(@data-bind, 'isForwardFreightSeller')]"))).get_attribute("value"))
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I've already tried this. Value is not on the HTML, so all that prints is an empty line. Is there a way to highlight the textbox and copy from it? – Clockknight Dec 21 '21 at 03:12
0

You should be able to use the following javascript snippet for this:

return arguments[0].value;

This is assuming you know how to execute javascript on an element.

anilk
  • 44
  • 1