def perform(self, driver, dry=False): driver.execute_script(''' var elem = arguments[0] elem.setAttribute("x-WebtalkInteracted", "1") ''', self.element) if dry and self.type=='click': self.highlight(driver) return if self.type == 'click': self.element.click() elif self.type == 'type': self.element.clear() self.element.send_keys(text_classification.untokenize_subcommand(self.params))
def evaluate(eval_corpus_file, theta, start_url): docs = gen_docs.get_all_docs(eval_corpus_file) random.shuffle(docs) docs = docs[:100] driver = web.start(start_url) correct_docs = 0 correct_cmds = 0 total_cmds = 0 for doc in docs: driver.get(start_url) doc_correct = True for cmd in doc: total_cmds += 1 text_cmd, (cmd_type, wtid, arg) = cmd # do it state = web.build_state(driver, web.tokenize_command(text_cmd)) actions = state.enumerate_actions() action, best_score, probs = state.get_action_probs(actions, theta) if action and \ action.type == cmd_type and \ action.element.get_attribute('x-wtid') == wtid and \ (action.params == None or text_classification.untokenize_subcommand(action.params).lower() == arg.lower()): correct_cmds += 1 else: print "Failed: ", action, " for ", text_cmd doc_correct = False if action: action.perform(driver) if doc_correct: correct_docs += 1 driver.quit() return float(correct_docs) / len(docs), float(correct_cmds) / total_cmds