<commit_before>"""
Qxf2 Services: Utility script to generate XPaths for the given URL
* Take the input URL from the user
* Parse the HTML content using beautifilsoup
* Find all Input and Button tags
* Guess the XPaths
* To run the script in Gitbash use command 'python -u utils/xpath_util.py'

"""

from selenium import webdriver
from bs4 import BeautifulSoup

class Xpath_Util:
    "Class to generate the xpaths"

    def __init__(self):
        self.elements = None
        self.guessable_elements = ['input','button']
        self.known_attribute_list = ['id','name','placeholder','value','type','title','class']

    def generate_xpath(self,soup):
        "generate the xpath"  
        result_flag = False
        try:
            for guessable_element in self.guessable_elements:
                self.elements = soup.find_all(guessable_element)                                
                for element in self.elements:                                   
                    if (not element.has_attr("type")) or (element.has_attr("type") and element['type'] != "hidden"):
                        for attr in self.known_attribute_list:                                                      
                            if element.has_attr(attr):                                                             
                                locator = self.guess_xpath(guessable_element,attr,element)                               
                                if len(driver.find_elements_by_xpath(locator))==1:
                                    result_flag = True                                   
                                    print locator.encode('utf-8')
                                    break<commit_msg>Modified the attribute lists<commit_after>"""
Qxf2 Services: Utility script to generate XPaths for the given URL
* Take the input URL from the user
* Parse the HTML content using beautifilsoup
* Find all Input and Button tags
* Guess the XPaths
* To run the script in Gitbash use command 'python -u utils/xpath_util.py'

"""

from selenium import webdriver
from bs4 import BeautifulSoup

class Xpath_Util:
    "Class to generate the xpaths"

    def __init__(self):
        self.elements = None
        self.guessable_elements = ['input','button']
        self.known_attribute_list = ['id','name','placeholder','value','title','type','class']

    def generate_xpath(self,soup):
        "generate the xpath"  
        result_flag = False
        try:
            for guessable_element in self.guessable_elements:
                self.elements = soup.find_all(guessable_element)                                
                for element in self.elements:                                   
                    if (not element.has_attr("type")) or (element.has_attr("type") and element['type'] != "hidden"):
                        for attr in self.known_attribute_list:                                                      
                            if element.has_attr(attr):                                                             
                                locator = self.guess_xpath(guessable_element,attr,element)                               
                                if len(driver.find_elements_by_xpath(locator))==1:
                                    result_flag = True                                   
                                    print locator.encode('utf-8')
                                    break
{'fraction_non_alphanumeric': 0.07375396139441083, 'fraction_numerical': 0.0023048112935753384, 'mean_word_length': 1.3302013422818793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6159006', 'n_tokens_mistral': 822, 'n_tokens_neox': 783, 'n_words': 220}