Issue in using dynamic XPATH in selenium - selenium

I have written the below code to identify the element in chrome and click on it, but later I realized that value for "#id" (u_jsonp_X_x) is keep on changing and that's causing fail to identify the element.
dr2.findElement(By.xpath("//*[#id='u_jsonp_2_4']/div/a[3]/span[1]")).click();
To resolve this issue, I have used below code based on my understanding but still not working
dr2.findElement(By.xpath("[starts-with(#id=(),'u_jsonp_2')]")).click();
Could you please help me to resolve this issue?

The XPath syntax in the second case is not correct, you meant:
dr2.findElement(By.xpath("//*[starts-with(#id, 'u_jsonp')]/div/a[3]/span[1]")).click();

Related

Unable to evaluate the expression Object has been collected

There is one object from one class which is not getting identified during the runtime or debugging.
The same object gets highlighted on devtools. I'm not understanding what is wrong over here.
Does anyone have any idea what is the cause of this issue?
Let me know if require more details.
The reason it was not getting highlighted during runtime was because it is the part of one iframe. After pointing my webDriver to the iframe and then the object , my code was running successfully.

Codeception ->see("String") fails but ->seeInSource("String") succeeds

Something is wrong with the AcceptanceTester->see() method for me. It can't see things that are plainly there in the source, as shown by the AcceptanceTester->seeInSource() method.
Here's my test, which runs in PHPBrowser within the WP-Browser implementation of Codeception:
public function testAfricaIsVisible(AcceptanceTester $I) {
$I->amOnPage('/');
$I->seeResponseCodeIs(200);
$I->seeInSource('Africa');
$I->see('Africa');
}
Here's the result I get:
As you can see, ->SeeInSource("Africa") works, but ->see("Africa") fails.
I understand that ->SeeInSource() sometimes "sees" things that ->see() doesn't, but in this case, the word "Africa" is link text that should be clearly visible with or without strip_tags() applied.
In this case, when I open up the Html link the word "Africa" is clearly visible:
Anyone have any idea why Codeception doesn't ->see() this text?
I figured it out. For anyone with a similar problem, the underlying issue was malformed HTML that was glossed over by Chrome/Firefox but screwed up the site as seen by Phpbrowser. I bet if I was using the WebDriver module instead, it would work.
The solution: Use an HTML validation tool and fix the reported syntax errors.
In this case it was a title tag with a single-quote in it, e.g. title='doesn't'

Frames issue using Watir-Webdriver and phantomjs

I'm writing test using Watir-Webdriver and phantomjs and I've got an issue with iframes.
I'm trying to get an element with the following code:
browser.frame(:index => 0).div(:id, "wrapper").exists?
and when I'm using phantomjs, it raise an error:
NameError: uninitialized constant Watir::FramedDriver::UnknownFrameException
but when I'm using chrome driver, the code above works properly and returns "true" value.
Any ideas how can I fix it? Or maybe there is any other way to get this element using phantomjs?
Any help will be appreciated. Thanks!
My guess is that ghostdriver does not have support for frames. I could not find an open issue related to frames in it's bug tracker: https://github.com/detro/ghostdriver/issues If you think it is a bug in ghostdriver, you should report it there.

Mysterious FireBug Error repeats with ExtJS

When debugging ExtJS 4 (tried both versions 4.1.0 and 4.1.1), FireBug repeatedly shows the following error: An invalid or illegal string was specified
http://docs.sencha.com/ext-js/4-1/extjs/ext-all.js
Line 18. It does not break on the error, though that option is specified. Additionally, neither my code or ext-debug.js and it's loader seem to actually call ext-all.js.
This error gets logged to Firebug's console about once per minute, which is annoying. What bothers me is that I cannot get the error to go away. Is this a FireBug bug? An ExtJS bug? Aliens? How can I debug the debugger?
I had the same problem before and I've solved it by removing a special character at the end of my JS file! (app.js I think)
It was weird, but the problem came from hidden special characters like: Zero-width non-joiner or Right-to-left mark.
Open another JS file but do not copy/paste your code there. Just write it again and check whether the problem exists or not.
And don't forget to check your data if you have some. As this article explains about the problem: http://www.ashorlivs.fr/javascript-jquery/article/an-invalid-or-illegal-string-was
For general debugging see this link http://www.sencha.com/learn/debugging-ext-js-applications/
You can also use ext-all-dev.js while in development mode.
There is another excellent tool on top of firebug, at this link http://www.illuminations-for-developers.com/
PS: I still didn't figured out how to post a comment. I guess it comes when I have more points/reputation. Hence adding it as an answer. thanks.

Selenium IDE:After Recording the Application Functionalities in IDE,i use the tool to run.But,it is showing error like:

[error] Element //div[#id='divProjects']/table/tbody/tr/td[6]/i not found
i tried to use xpather,firebug inorder to find the id's and values of the object.But,it is not working for me.
please help me to solve my issue.
You can share the IDE script, it'll make easy to resolve the issue. You have to verify that you have got to the element when you are trying to perform any action on it.
Your xpath needs to be more relative. One thing you can try is to change the xpath to xpath:relative while recording in IDE. You can find this option on clicking on the dropdown