Reputation: 77
I m trying to find and fill form with Selenium but I have to select id from a mysql table. There is no problem to fetchone item with mysql. The problem is when I add variable to selenium code, it gives me this error:
Invalid locate values passed in.
Here is my code:
import pymysql
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='xxx', db='python')
cur = conn.cursor()
z=1
cur.execute("SELECT id_1 FROM deneme WHERE id=%s" %(z))
search = cur.fetchone()
chromedriver = 'C:\\chromedriver.exe'
browser = webdriver.Chrome(chromedriver)
browser.get('https://e-okul.meb.gov.tr/')
a = input ("input something when the page is loaded")
Y = input ("write your comments")
element = find_element_by_id(search)
element.send_keys (y)
It is probably because of the fetchone code gives the element with some punctuation. But how can I solve this problem?
Thanks
Upvotes: 1
Views: 268
Reputation: 77
I solved my problem by adding [0] at the end of the fetchone()
method call.
search = cur.fetchone()[0]
Upvotes: 1