Reputation: 1
def build(self):
screen = Screen()
type = TextInput(text="Enter job domain",pos = (270,380),size_hint =(.3, .1))
btn = Button(text="Job Search",size_hint =(.2, .2), pos =(300, 250),background_color =(0, 0, 1, 1),)
btn.bind(on_press=self.callback)
screen.add_widget(type)
screen.add_widget(btn)
return screen
def callback(self, event):
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://indeed.com')
search_job = driver.find_element_by_xpath('//*[@id="text-input-what"]')
search_job.send_keys(['data science'])
initial_search_button = driver.find_element_by_xpath("//*[@id='whatWhereFormId']/div[3]/button")
initial_search_button.click()
Here I want to use the text from the type variable initialized with a textInput variable in the def build(self) function and use it in the def callback(self,event) function in the search_job.send_keys(['']) part
Upvotes: 0
Views: 66
Reputation: 38962
If you want to use the text
from a TextInput
, just save a reference to that TextInput
(perhaps call it self.type
):
def build(self):
screen = Screen()
self.type = TextInput(text="Enter job domain",pos = (270,380),size_hint =(.3, .1))
btn = Button(text="Job Search",size_hint =(.2, .2), pos =(300, 250),background_color =(0, 0, 1, 1),)
btn.bind(on_press=self.callback)
screen.add_widget(self.type)
screen.add_widget(btn)
return screen
Then use that reference wherever you need it:
def callback(self, event):
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://indeed.com')
search_job = driver.find_element_by_xpath('//*[@id="text-input-what"]')
search_job.send_keys([self.type.text])
initial_search_button = driver.find_element_by_xpath("//*[@id='whatWhereFormId']/div[3]/button")
initial_search_button.click()
Upvotes: 0