From this page:
https://permits.losgatosca.gov/CitizenAccess/default.aspx
I'm trying to push the 'Search Permits' button under Building Permits.
This is its xpath:
//*[#id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span
This is the code I'm using:
url = "https://permits.losgatosca.gov/CitizenAccess/default.aspx"
driver_1 = webdriver.Firefox()
driver_1.get(url)
NEXT_BUTTON_XPATH = '//*[#id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span'
# "//*[#id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span"
button = driver_1.find_element_by_xpath(NEXT_BUTTON_XPATH)
button.click()
But I get this message:
selenium.common.exceptions.NoSuchElementException: Message: Unable to
locate element:
{"method":"xpath","selector":"//*[#id=\"ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl\"]/span"}
Stacktrace:
There is a frame with id ACAFrame, you need to switch that frame first as below :-
driver_1.switch_to_frame("ACAFrame")
NEXT_BUTTON_XPATH = '//*[#id="ctl00_PlaceHolderMain_TabDataList_TabsDataList_ctl01_LinksDataList_ctl00_LinkItemUrl"]/span'
button = driver_1.find_element_by_xpath(NEXT_BUTTON_XPATH)
Edited..
After clicking Search Permits to perform action on opened form you should try as below :-
driver_1.switch_to.default_content()
driver_1.switch_to_frame("ACAFrame")
# now find your desire element
Hope it will work...:)
Related
I am having trouble with finding the compose button in Gmail. Every time I run it I get the following error message saying that the element doesn't exist
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#class="T-I T-I-KE L3"]"}
I have tried multiple things including:
ComposeButton = driver.find_element(By.XPATH, '//*[#jscontroller="eIu7Db"]')
ComposeButton = driver.find_element(By.XPATH, '//*[#class="T-I T-I-KE L3"]')
ComposeButton = driver.find_element(By.XPATH, '//*[#jsaction="click:dlrqf; clickmod:dlrqf"]')
They have all returned with the same error message
How do I access the compose button?
The greyed out part of the HTML in the linked image is for the compose button
Try this:
find_element(By.XPATH, "//div[#class='aic']/div/div")
This Worked for me
driver.find_element(By.CSS_SELECTOR, "[gh='cm']").click()
(N.B = change the word driver as per your code)
Hello first. Im try to make a bot which can make a list about your followers and Im using selenium/python for this. Now Im tying to click followers button on my profile but I guess something goes wrong about xpath, how can I fix this.
def followers(self):
self.browser.get("https://www.instagram.com/" + instagramLoginInfo.username +"/")
sleep(1)
followerslink = self.browser.find_element_by_xpath('//*[#id="react-root"]/section/main/div/ul/li[2]/a')
followerslink.click()
sleep(5)
followers = self.browser.find_element_by_css_selector("div[role=dialog] ul").find_elements_by_css_selector("li")
for user in followers:
link = user.find_element_by_css_selector("a").get_attribure("href")
print(link)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="react-root"]/section/main/div/ul/li[2]/a"}
(Session info: chrome=94.0.4606.61)
I am trying to locate a button according to one of the texts that are on it. The compiler gives me this message: )
...is not a valid XPath expression.
vyber2 = driver.find_elements_by_xpath( '//*[contains(text(), " komplexe Behandlung \"Classic\" ")]')
On the photo is a picture of the dropdown. I need to locate the package name on one of the options and click it. (For example, I need to click on the "Komplexe Behandlung Classic" package as shown on this picture.
My code to open the dropdown menu:
`#open the dropdown menu
vyber1 = driver.find_element_by_xpath(
'//*[#id="packageSelectorContainer"]/div[2]/div/div[1]/div[2]/div')
# Make click in that button
ActionChains(driver).move_to_element(vyber1).click(vyber1).perform()
#wait again
timeout = 5
WebDriverWait(driver, timeout)
try:
element_present = EC.presence_of_element_located((By.ID, '//*[#id="packageSelectorContainer"]/div[2]/div/div[1]/div[2]/ul/li[3]'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
#pick the desired package based on its name
vyber2 = driver.find_elements_by_xpath(
'//*[#id="packageSelectorContainer"]/div[2]/div/div[1]/div[2]/ul/li[3]')
# Make click in that button
ActionChains(driver).move_to(vyber2).click(vyber2).perform()`
Thanks for your help!
One way to grab button options with text komplexe Behandlung "Classic" that are not currently selected is to use Javascript via driver.execute_script:
from selenium import webdriver
d = webdriver.Chrome('/path/to/chromedriver')
d.get('https://www.sanatoriums.com/de/karlsbad/kurhotel-imperial-991/preise-zimmer?ar=2021-09-18&de=2021-10-02&ro=120&se=fbt')
elems = d.execute_script("""
function* get_buttons(text){
for (var i of document.querySelectorAll('div.flex-item.person-package.dropdown ul.dropdown-menu li.flex-grid')){
if (!i.getAttribute('class').includes(' selected')){
if (i.querySelector('div.package-title').textContent.includes(text)){
yield i
}
}
}
}
return [...get_buttons('komplexe Behandlung \"Classic\"')]
""")
I'm trying to open a website using Selenium, find a specific search box within it and fill it with a company name (MAGAZINE LUIZA S.A. in the example) and then click the "Search" button right next to the search box, since it will not work if I just hit "enter".
nav = webdriver.Edge()
nav.implicitly_wait(10)
nav.get('http://www.b3.com.br/pt_br/produtos-e-servicos/negociacao/renda-variavel/empresas-listadas.htm')
nav.find_element_by_xpath("/html/body/form/div[3]/div[1]/div/div/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/div[1]/label/span[1]/input[1]").send_keys('MAGAZINE LUIZA S.A.')
nav.find_elements_by_xpath('/html/body/form/div[3]/div[1]/div/div/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/div[2]/input').click()
And I get the Xpath of the search bar and search button by inspecting them and "copying full Xpath" in Microsoft Edge.
Problem is I get this error:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/form/div[3]/div[1]/div/div/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/div[1]/label/span[1]/input[1]"}
(Session info: MicrosoftEdge=91.0.864.54)
But I have verified that I have copied and pasted the correct Xpaths for both the commands. Can anyone help?
You need to handle iframe, that XPath is relative to iframe.
This is your modified code
nav = webdriver.Edge()
nav.implicitly_wait(10)
nav.get('http://www.b3.com.br/pt_br/produtos-e-servicos/negociacao/renda-variavel/empresas-listadas.htm')
iframe = nav.find_element_by_xpath('/html/body/main/div[4]/div/div[1]/div[1]/div/form/section/div/div/div/iframe')
nav.switch_to.frame(iframe)
inp = nav.find_element_by_xpath("/html/body/form/div[3]/div[1]/div/div/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/div[1]/label/span[1]/input[1]")
inp.send_keys('MAGAZINE LUIZA S.A.')
nav.find_element_by_xpath('/html/body/form/div[3]/div[1]/div/div/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/div[2]/input').click()
I am trying to click on the profile picture on top right to be able to logout of the website.
This is Cisco's license portal website "Logout" link; when you click on the profile picture, it drops down with a "Logout" link.
I can navigate through the body without any issues, but whenever I try to access the header of the site, it fails to find the element.
Using Selenium Chrome driver version 87 with Python
I can't seem to access that Profile Picture highlighted in red in order to logout with chrome selenium driver, it keeps telling me 'Element not found' using the ID or XPATH:
################ Log out ##############################
print('>>> Logging out of Cisco Cloud website')
logout = WebDriverWait(browser, element_timeout,ignored_exceptions=ignored_exceptions)\
.until(EC.presence_of_element_located((By.XPATH, '//*[#id="fwt-profile-button-loggedout"]')))
time.sleep(2)
logout = browser.find_element_by_xpath('//*[#id="fwt-profile-button-loggedout"]')
logout.click()
time.sleep(1)
logout1 = WebDriverWait(browser, element_timeout,ignored_exceptions=ignored_exceptions)\
.until(EC.presence_of_element_located((By.LINK_TEXT, 'Logout')))
time.sleep(2)
logout1 = browser.find_element_by_link_text('Logout')
logout1.click()
time.sleep(5)
------------------
I tried this based on this answer, but still cannot get it to find the element:
https://stackoverflow.com/a/48756722/12288943
def expand_shadow_element(element):
shadow_root = browser.execute_script('return arguments[0].shadowRoot', element)
return shadow_root
################# Log out ##############################
print('>>> Logging out of Cisco Cloud website')
logout1 = browser.find_element_by_xpath('//*[#id="overlayBlack"]/csc-header')
shadow_root1 = expand_shadow_element(logout1)
logout2 = browser.find_element_by_xpath('//*[#id="overlayBlack"]/csc-header//div')
shadow_root2 = expand_shadow_element(logout2)
logout = browser.find_element_by_id('fwt-profile-button-loggedout')
time.sleep(2)
logout.click()
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="overlayBlack"]/csc-header//div"}
(Session info: chrome=87.0.4280.88)
There is a #shadow-root(0) inside the 'csc-header' tag. The element you're trying access is inside shadow-root. I think that's why you are getting an 'Element not found' error. You have to navigate into shadow first. Hope this points you in the right direction.
<csc-header>
#shadow-root (open)
<svg id='fwt-profile-button-loggedout'></svg>
</csc-header>