2

I am trying to extract the text that is generated in a text box based on values I enter into another text box. I looked in the inspect element and there is no signs of the values at all, and the 'Value' has nothing in it even though the box is populated.

I am using selenium in Python to try perform this. I am only working with 1 currently, but will be setting up a loop to do thousands hence why I need this automated.

Below is the code in the page (Ordinance Survey Ireland Website)

<td width="25%" class="form">Latitude:</td>
<td class="form">
   <input type="text" name="GeodeticLatitude" type="number" size="10" maxlength="2" value="">
   deg
   <input type="text" name="GeodeticLatitudeMin" size="2" maxlength="2" value="0">
   min
   <input type="text" name="GeodeticLatitudeSec" size="8" maxlength="8" value="0">
   sec
</td>

Below is the code that I am currently working with to attempt to extract the values

browser = webdriver.Chrome()

browser.get("https://gnss.osi.ie/new-converter/")

def find():
    python_button = browser.find_elements_by_xpath("//input[@name='IrishGridEasting']")[0]
    python_button.send_keys("316600")
    python_button = browser.find_elements_by_xpath("//input[@name='IrishGridNorthing']")[0]
    python_button.send_keys("229500")
    python_button = browser.find_elements_by_xpath("//td[@class='form']/button[@type='button']")[1]
    python_button.click()

    latDeg = browser.find_elements_by_xpath("//input[@name='GeodeticLatitude']")
    print(latDeg)

I have attempted to add in options such as .text, .getText(), .getAttribute and .get_attribute but they do not return the text box value

Then below screenshot shows what I am trying to retrieve.

The red boxes is the number I am inserting, the green box represents what I want to extract.

Screenshot of webpage

1
  • Have you tried this: input.get_attribute('value') or input.get_attribute('innerText')? Commented Jan 22, 2020 at 12:15

1 Answer 1

3

You have to provide time.sleep(1) since the value generating your script unable to sync this.Try WebDriverWait and use get_attribute('value') to get the value from input fields.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
driver=webdriver.Chrome()
driver.get('https://gnss.osi.ie/new-converter/')
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//input[@name='IrishGridEasting']"))).send_keys("316600")
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//input[@name='IrishGridNorthing']"))).send_keys("229500")
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//tr[contains(.,'Irish Grid Co-ordinates:')]//button[text()='Convert']"))).click()
time.sleep(1)
print(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"input[name='GeodeticLatitude'][value]"))).get_attribute('value'))
Sign up to request clarification or add additional context in comments.

Comments

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.