-1

Hey guys im completely lost. I've tried everything find_by_xpath/by_class etc but it just won't work. I always get the can't find element error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ms-Button _3vq4lJQg9EQ9QnW_2iLCJo ms-Button--action ms-Button--command root-205"} (Session info: chrome=91.0.4472.77)

next_but=web.find_element_by_id('idSIButton9')
time.sleep(1)
next_but.click()
pwin=web.find_element_by_id("i0118")
pwin.send_keys(PW)
time.sleep(2)
next_but2=web.find_element_by_id("idSIButton9")
next_but2.click()
web.get(link)
rules=web.find_element_by_class_name('ms-Button _3vq4lJQg9EQ9QnW_2iLCJo ms-Button--action ms-Button--command root-205')

I've also tried that the WebDriver waits for the element to load and it seems that the element isn't in another frame.Thats the button I'd like to be pressed

Please help me im completely lost thanks in advance

Lost_coder
  • 94
  • 8

4 Answers4

1

I believe this should be resolve with WebDriverWait :

Code to try it out :

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Regeln']/ancestor::button"))).click()
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • Hey is that correct? : WebDriverWait(web, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'//*[@id="ModalFocusTrapZone60"]/div[2]/div/div[3]/div/div'))) – Lost_coder Jun 03 '21 at 19:09
  • Is the URL public ? I can have a look. cause I think we can improve `[@id="ModalFocusTrapZone60"]/div[2]/div/div[3]/div/div` – cruisepandey Jun 03 '21 at 19:10
  • @cruisepandey just curious, how do you say its inside iframe? – itronic1990 Jun 03 '21 at 19:12
  • yeah probably not I get this error message selenium.common.exceptions.TimeoutException: Message: – Lost_coder Jun 03 '21 at 19:12
  • Well sort of its the settings page from outlook.live.com – Lost_coder Jun 03 '21 at 19:14
  • 1
    @itronic1990 : most of the time in my experience here OP do not switch to iframe, and moreover see his HTML, by seeing it, to me it looks like an iframe but again that's a guess – cruisepandey Jun 03 '21 at 19:14
  • @Lost_coder : Please share exact URL – cruisepandey Jun 03 '21 at 19:14
  • yeah sure https://outlook.live.com/mail/0/options/mail/layout – Lost_coder Jun 03 '21 at 19:18
  • @Lost_coder : How can I reach to that button ? Is login required ? – cruisepandey Jun 03 '21 at 19:19
  • and what do I have to do to reach that button ? I am logged in – cruisepandey Jun 03 '21 at 19:30
  • go to settings at the top and then on the right there should be a window and on the bottom it says something like show more outlook settings click that and then you're on the exact page. I try to click the "Rules" button and then create my own rule automatically – Lost_coder Jun 03 '21 at 19:34
  • is it `Regeln` in your language ? – cruisepandey Jun 03 '21 at 19:39
  • 1
    yeah Rules is Regeln in german dude thanks for your help I really appreciate it – Lost_coder Jun 03 '21 at 19:40
  • @Lost_coder : No problem mate. I have updated the code above, check out and let me know, btw Germany is my dream country :) – cruisepandey Jun 03 '21 at 19:45
  • Thanks dude I don't live in Germany I live in Switzerland but parts of Switzerland share the same language as Germany. – Lost_coder Jun 03 '21 at 19:47
  • @Lost_coder : That's even beautiful. Anyway don't forget to accept this answer if it works for you :) – cruisepandey Jun 03 '21 at 19:48
  • OMG it worked you are literally THE GOAT one problem less could you briefly explain how you did it otherwise ill post the same question with a different button in 10 mins :) Dude you're awesome – Lost_coder Jun 03 '21 at 19:50
  • @Lost_coder : it's the xpath dude that played real game here. As you can see from the above we have targetted the text which is Regeln and ancestor of that particular button. Used explicit wait - webdriver wait to wait for the element to be clickable and then click it. – cruisepandey Jun 03 '21 at 19:57
  • 1
    Ok let me try it for the next button you are great – Lost_coder Jun 03 '21 at 19:59
0

Looks like the class name you are using is dynamic. Try some thing like this

driver.find_element_by_xpath(".//button[text()='button text here']").click()

Update:

driver.find_element_by_xpath(".//span[text()='Regeln']").click()
itronic1990
  • 1,231
  • 2
  • 4
  • 18
0

That's some ugly HTML. Try this:

driver.find_element_by_xpath("(//div[@data-focuszone-id='FocusZone197']/button)[4]")
JD2775
  • 3,658
  • 7
  • 30
  • 52
0

Most of the HTML here looks dynamic which makes it hard to build bulletproof xpaths.
I would use the following as the aria-label should mostly stay static over time:

driver.find_element_by_xpath("(//div[@aria-label='Unterregisterkarte der Kategorie "E-Mail"']//button)[4]")