0
I’m trying to automate a routine but I’m not getting ahead on a part I have to select a combobox from a page with Selenium.
The field I want to fill in is as follows,
In all fields until I got here, I was able to navigate with "find_element_by_id", but in this case it does not work.
Last attempt I made was with "find_element_by_xpath" but without success.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
Chrome_exe = r'C:\Projetos\Integração\chromedriver.exe'
user = "xxxxxxx"
pwd = "xxxxxxx"
driver = webdriver.Chrome(executable_path=Chrome_exe)
driver.get("https://xxxxxxxxx/#/login?to=~2Ffollow_up~2Factual_budget")
elem = driver.find_element_by_id("username")
elem.send_keys(user)
elem = driver.find_element_by_name("password")
elem.send_keys(pwd)
elem.send_keys(Keys.RETURN)
elem = driver.find_element_by_xpath("html/body/div/div/div/fildset/div/div/div/select").click();
It returns the following error,
--------------------------------------------------------------------------- Nosuchelementexception Traceback (Most recent call last) in -----> 1 elem = driver.find_element_by_xpath("html/body/div/div/div/fildset/div/div/div/select"). click();
c: program files python37 lib site-Packages Selenium webdriver remote webdriver.py in find_element_by_xpath(self, xpath) 392 element = driver.find_element_by_xpath('//div/td1') 393 "" --> 394 Return self.find_element(by=By.XPATH, value=xpath) 395 396 def find_elements_by_xpath(self, xpath):
c: program files python37 lib site-Packages Selenium webdriver remote webdriver.py in find_element(self, by, value) 976 Return self.execute(Command.FIND_ELEMENT, { 977 'using': by, --> 978 'value': value})['value'] 979 980 def find_elements(self, by=By.ID, value=None):
c: program files python37 lib site-Packages Selenium webdriver remote webdriver.py in execute(self, driver_command, params) 319 Sponse = self.command_executor.execute(driver_command, params) 320 if Sponse: --> 321 self.error_handler.check_response(Response) 322 sponse['value'] = self. _unwrap_value( 323 Answer.get('value', None))
c: program files python37 lib site-Packages Selenium webdriver remote errorhandler.py in check_response(self, Sponse) 240 alert_text = value['Alert']. get('text') 241 raise exception_class(message, screen, stacktrace, alert_text) --> 242 raise exception_class(message, screen, stacktrace) 243 244 def _value_or_default(self, obj, key, default):
Nosuchelementexception: Message: no such element: Unable to locate element: {"method":"xpath","selector":"html/body/div/div/div/fildset/div/div/div/select"} (Session info: Chrome=75.0.3770.142)
Can anyone help me? Grateful!
Felipe, I’m sorry about the stupid question, but I don’t have much experience with the web. Is there any way I can take this path in some more roundabout way in Chrome?
– Pedro Adamo
Pedro is also not an expert in this area and I have always used xpath as the last resource so I can’t tell you if there is a better way. I asked you to check the path because it is very common using xpath the error be just there.
– Filipe Gonçalves
Hi, in Selenium you can do some action on the components via ID , or class name or xpath. this app you are automating uses Angular-JS can try to access via css, try to find explanations on the official page Lenium, the basic is driver.findElement(By.cssSelector("input[ng-model="tableName"]")). Using xpath may give problem in the future any change in Cod may not find the UI.
– stack.cardoso