-1

Hi I do have the below codes for the Save Button that needs to be clicked using Python Selenium.

1 <button ngcontent-jkv-c423-" " type="button" mat-raised-button=" " id="btnSave" class="mat-focus-indicator mat-raised-button mat-button-base mat-none mat_animation-noopable ng-star-inserted" data-dtname="Work.save"> 
2 <span class="mat-button-wrapper">
3 <span ngcontent-jkv-c423="" data-dtname="Work.save">
4 <i _ngcontent-jkv-c423-"" aria-hidden="true" class="fas fa-save">
5 </i> 
6 "Save "
7 </span>
8 </span>
9 <span matripple=" " class="mat-ripple mat-button-ripple">
10 </span><span class="mat-button-focus-overlay"></span>
11 </button>

T tried the following codes:

1 driver.find_element_by_xpath("//span[contains(text(),'Save ')]").click()
2 driver.find_element_by_class_name("fas fa-save").click()
3 driver.find_element_by_class_name("//span[@data-dtname='Work.save']").click()

But all the above codes are throwing errors.

Is there any alternative ways to do this??

Thanks in advance.

2 Answers2

1

Save looks like a text node so, you can not use this xpath :

//span[contains(text(),'Save ')]

your 2nd attempt looks invalid cause :-

class name with space are not supported.

and 3rd attempt :-

find_element_by_class_name("//span[@data-dtname='WorkQueue.save']")

you are passing xpath, in class name.

so, Why not id ?

driver.find_element_by_id('btnSave').click()

Update 1 :

can you launch browser in full screen mode like this.

driver.get('https://google.com')
driver.maximize_window()
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

As far as i understood another element is covering the element which i wanted to click , so i did the below code:

save_ele=driver.findelement_by_xpath("**full xpath of the element**)
driver.execute_script("arguments[0].click()",save_ele)

This is working fine for me.