0

I am trying to click a tab called source control,That tab has an id which is dynamically generated.on looking online ,tried below methods but still no use

Tried the below xpath:

//li[@class="menu-item"]/a/strong[text(),Source Control]')
//li[@class="menu-item"]//a//text()[preceding-sibling::strong][normalize-space()!='']
//li//a[starts-with(id,"aui-uid-")]/strong[text(),Source Control]

Code that i am using

Sourcecontrol=driver.find_element_by_xpath('//li[@class="menu-item"]/a/strong[text(),Source Control]')
if not Sourcecontrol:
    print("No element found")  
else:
    Sourcecontrol.click();

HTML

<li class="menu-item" role="presentation">
                    <a href="link" id="aui-uid-4" role="tab" aria-selected="false"><strong>Source Control</strong></a>
                </li>

1 Answer 1

1

Use the following xpath.It will search the substring inside anchor element.Try use following options

try:
 Sourcecontrol=driver.find_element_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]')
 Sourcecontrol.click();
except:
 print("No element found")

Or

if len(driver.find_elements_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]'))>0:
   Sourcecontrol = driver.find_element_by_xpath('//li[@class="menu-item"]/a[contains(.,"Source Control")]')
   Sourcecontrol.click();
else:
    print("No element found")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.