Home > Mobile >  Using Python to fill in a web text box with an If Statemen
Using Python to fill in a web text box with an If Statemen

Time:11-04

Hello everyone I am new to Python and I wanted to see if someone can help. I am trying to automate text input on a website. I am trying to run a code that says if the input box is empty to type 4.00 if not to press the down key. An image is provided to help understand the issue. Thanks in advance.

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import pyautogui





driver = webdriver.Chrome()
driver.maximize_window()

login = driver.get("somesite")
sleep = time.sleep(10)

sleep

select_applications = driver.find_element(By.XPATH,"/html/body/div[3]/div[2]/div[1]/div[1]/div[1]/div/div/div/div/header/div[3]/div[3]/div[1]/button").click()
time.sleep(3)

select_app = driver.find_element(By.XPATH,"/html/body/div[3]/div[2]/div[1]/div[1]/div[1]/div/div/div/div/header/div[3]/div[3]/div[2]/div/div[2]/div/div/div[5]/div/div[33]/div/div/div[1]/span/a/img").click()

time.sleep(10)

py = pyautogui

py.moveTo('Wed.PNG')

py.move(0,35)

send_click = py.click()

if send_click = " ": 
py.hotkey("4.00)
else:
py.hotkey("down")



I try running the If statement but I got no results. enter image description here

CodePudding user response:

You're checking for a space character in the if statement.

Replace

if send_click = " ":

with

if send_click == "":

CodePudding user response:

As it's said if send_click = " " needs to be replaced by if send_click = "" And, maybe it's a copy-paste error but there is a mistake with the identation (that's how Python understands which blocks of code are in the if statement). There should be 4 spaces before py.hotkey("4.00) and the same before py.hotkey("down"). BTW you missed quote mark in py.hotkey("4.00) Now it looks like this:

if send_click = " ": 
py.hotkey("4.00)
else:
py.hotkey("down")

But should be:

if send_click = "": 
    py.hotkey("4.00")
else:
    py.hotkey("down")
  • Related